Pandas Tips: Easy Tricks for Better Data Work

Tahera Firdose
5 min readDec 13, 2023

Hey there! Today, we’re going to explore some cool yet simple tricks in Pandas, a Python tool for handling data. These tricks are not only easy but also powerful, helping you work smarter with your data.

1. Picking Data Easily with query

Problem: Imagine having a huge list of data and you need to find something specific. It can be like looking for a needle in a haystack.

Solution: The query method. It's like using a magnet to find that needle. You just ask a question and it finds the answers.

Here, df is your list of data. You're asking to find all entries where the age is over 30 and salary is more than 50,000. It's a quick way to filter your data.

2. Adding New Info Easily with np.select

Problem: Sometimes, you want to add new information based on what you already have. Doing this one by one can take forever.

Solution: Use np.select. It's like having a smart assistant who can categorize things for you.

This creates a new category in your data. If someone’s under 30, they’re labeled ‘Young’; if 30 or older, ‘Old’. Anyone who doesn’t fit these conditions gets an ‘Unknown’ label.

3. Making Words Uppercase Quickly with Vectorization

Problem: What if you need to change the text in your data, like making all names uppercase…

--

--

Tahera Firdose

Datascience - Knowledge grows exponentially when it is shared