PANDAS Cheatsheet
PANDAS Cheatsheet
Pandas Cheatsheet
KEY IMPORTS
We’ll use shorthand in this Import these to start
cheat sheet import pandas as pd
import numpy as np
df - A pandas DataFrame
object
s - A pandas Series object
IMPORTING DATA
If file you are importing is in different directory so in place of filename, write path
of your file.
CODE WORKING
Pandas Cheatsheet 1
CODE WORKING
EXPORTING DATA
CODE WORKING
df.to_sql(table_name,
Writes to a SQL table
connection_object)
VIEWING/INSPECTING DATA
CODE WORKING
SELECTION
CODE WORKING
Pandas Cheatsheet 2
DATA CLEANING
CODE WORKING
s.replace([1, 3], ['one', 'three']) Replaces all 1 with ‘one’and 3 with ‘three’
df.rename(columns={'old_name':
Selective renaming
'new_name'})
df.set_index('column_one') Changes the index
df[(df[col] > 5) & (df[col] < 7)] Rows where 7 > col > 5
Pandas Cheatsheet 3
CODE WORKING
JOIN/COMBINE
CODE WORKING
STATISTICS
CODE WORKING
Pandas Cheatsheet 4