Member-only story
4 awesome Pandas tricks every data scientist should know
Welcome back! Pandas is one of the most important package a data scientist could know, so let’s talk about some tricks you can use with Pandas that can help increase your work flow. One quick thing to note, although these specific tricks range in use, they could be implemented in most projects out there that use this package! With that boring introduction out of the way, let’s get started!
Quick note, we’ll be using a sample data frame for these tricks, here is the code to develop the sample data frame:
import pandas as pdd = {'name': ['Sam', 'Mike', 'Lisa'], 'items': [24, 44, 55]}df = pd.DataFrame(data=d)
Querying Data
Starting off, we have the query function within Pandas. With this specific method, it allows us to pull specific points from our data with certain criteria, let’s use the top data frame as an example, let’s say we wanted to export people named Sam from our data frame, we can do so with the following command:
df.query('name == "Sam"')
This will display the matching criteria:
It also works with amounts, let’s say we wanted to see people who bought more than 20 items, we can utilize a greater than statement like this: