Let's face it. Pandas API can be pretty confusing. They sometimes use
camelCase instead of
pascal_case and the names of the functions are often not the easiest to remember. Is it
values_counts? I never know and that's why I end up searching for the same things over and over again.
I decided to make this notebook to put all the common things I'm googling into one place. These are the most common questions I found useful on StackOverflow. Every answer will link to the original post whose authors deserve all the credit.
Select rows based on column values from Pandas DataFrame
Columns that equal value
Columns that do not equal value
Select multiple columns of Pandas DataFrame
Iterate over rows of Pandas DataFrame
Don't do it! It's not idiomatic. Vectorise your operations instead. Click here for full reasoning
Rename columns of Pandas DataFrame
All at once
Delete columns of Pandas DataFrame
Get row/column count of Pandas DataFrame
Get list of column headers of Pandas DataFrame
Rearange the order of columns of Pandas DataFrame
Add new column to Pandas DataFrame
Add new rom to Pandas DataFrame
Don't do it! It's slow and unidiomatic. Gather all the data first and only create the dataframe after.
Drop rows whose values in a certain column is NaN in Pandas DataFrame
Change column type in Pandas DataFrame
Delete row based on value of particular column from Pandas DataFrame
See also "how to select rows based on column values" for other options
Save Pandas DataFrame to a CSV
Is it count_values or values_count or what?
It's value_counts. If you asked this question, you might wanna try Deepnote which has autocomplete and would tell you.