pandas Cheat Sheet (via yhat)

pandas cheat sheetThe folks over at yhat just released a cheat sheet for pandas.  You can download the cheat sheet in PDF for here.

There’s a couple important functions that I use all the time missing from their cheat sheet (actually….there are a lot of things missing, but its a great starter cheat sheet).

A few things that I use all the time with pandas dataframes that are worth collecting in one place are provided below.

Renaming columns in a pandas dataframe:

Iterating over a pandas dataframe:

Splitting pandas dataframe into chunks:

The function plus the function call will split a pandas dataframe (or list for that matter) into NUM_CHUNKS chunks. I use this often when working with the multiprocessing libary.

Accessing the value of a specific cell:

This will give you the value of the last row’s “COLUMN” cell.  This may not be the ‘best’ way to do it, but it gets the value

Getting rows matching a condition:

The below will get all rows in a pandas dataframe that match the criteria.  In addition to finding equality, you can do all the logical operators.

Getting rows matching multiple conditions:

This gets rows that match a criteria in COLUMN1 and those that match another criteria in COLUMN2

Author: Eric Brown

Eric D. Brown , D.Sc. has a doctorate in Information Systems with a specialization in Data Sciences, Decision Support and Knowledge Management. He writes about utilizing python for data analytics at pythondata.com and the crossroads of technology and strategy at ericbrown.com

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
eric@ericbrown.comKarlijn Willems Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Karlijn Willems
Guest

Hi Eric!
You’re right that there is quite some stuff missing from this cheat sheet, but it was my intention when I first started out to make multiple cheat sheets, so you can probably expect more in the future. The code that you have added is amazing and I wanted to thank you for the feedback!

Thanks!
Karlijn

PS. If you want, check out my latest NumPy cheat sheet (https://www.datacamp.com/community/blog/python-numpy-cheat-sheet); would love to hear your feedback!