Pandas tricks I wish I knew earlier
Welcome back! Pandas is one of the best Python packages for data science, so let’s talk about some Pandas tricks I wish I knew earlier. Now, although these tricks range in use, you can probably implement these in a majority of your projects. 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)
Counting Number Of Values
First up we have the value_counts function, this specific function is extremely useful when determining the total amount values for your data, using the above dataset, this is how it could possibly look like:
df['name'].value_counts()
This will print out essentially the amount of instances for these values:
This can be extremely useful when determining the amount of values in your dataset.
Querying Data
Next up 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…