Show Menu
Cheatography

Pandas Library Cheat Sheet (DRAFT) by

Cheat sheet for Pandas Library

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Pandas Data Structure

Series
A one-di­men­sional labeled array a capable of holding any data type
>>> s = pd.Ser­ies([3, -5, 7, 4], index=­['a', 'b', 'c', 'd'])
DataFrame
A two-di­men­sional labeled data structure with columns of potent­ially different types
>>> data = {'Coun­try': ['Belg­ium', 'India', 'Brazil'], 'Capital': ['Brus­sels', 'New Delhi', 'Brasí­lia'], 'Popul­ation': [11190846, 130317­1035, 207847­528]}

I/O

Read and Write to CSV
>>> pd.rea­d_csv( , header­=None, nrows=5)
 
>>> df.to_­csv­('m­yDa­taF­ram­e.csv')
Read and Write to Excel
>>> pd.rea­d_e­xcel( )
 
>>> df.to_­exc­el(­'di­r/m­yDa­taF­ram­e.x­lsx', sheet_­nam­e='­She­et1')
 

Applying Functions

Apply function elemen­t-wise
>>> f = lambda x: x*2
 
>>> df.app­ly(f)
 
>>> df.app­lym­ap(f)

Basic Inform­ation

(rows,­col­umns)
>>> df.shape
Describe index
>>> df.index
Describe DataFrame columns
>>> df.columns
Info on DataFrame
>>> df.info()
 

Data Alignment

NA values are introduced in the indices that don’t overlap:
>>> s3 = pd.Ser­ies([7, -2, 3], index=­['a', 'c', 'd'])
 
>>> s + s3 a 10.0 b NaN c 5.0 d 7.0

Data Alignment

NA values are introduced in the indices that don’t overlap:
>>> s3 = pd.Ser­ies([7, -2, 3], index=­['a', 'c', 'd'])
 
>>> s + s3 a 10.0 b NaN c 5.0 d 7.0

Data Alignment

NA values are introduced in the indices that don’t overlap:
>>> s3 = pd.Ser­ies([7, -2, 3], index=­['a', 'c', 'd'])
 
>>> s + s3 a 10.0 b NaN c 5.0 d 7.0

Data Alignment

NA values are introduced in the indices that don’t overlap:
>>> s3 = pd.Ser­ies([7, -2, 3], index=­['a', 'c', 'd'])
 
>>> s + s3 a 10.0 b NaN c 5.0 d 7.0