PYTHON PANDAS Cheat Sheet
PYTHON PANDAS Cheat Sheet
installing pandas to delete a row - [axis=0 means rows] df.set_index('column_‐ Change the
pip install pandas new_df = df.drop([2,3],axis = 0) one') index with a new
pip install pandas #this drops the row with index column
Inplace
NOTE df[col] Returns column with label
df.merge(df2) gives you a copy of df col as Series
merged with df2. you may save it to a new df[[col1, Returns multiple columns as
variable. ex df3=df.merge(df2) col2]] a new DataFrame
if you want to merge df2 to df right away use Country Capital Population
inplace. df.merge(df2,inplace=True) 1 Belgium Brussels 11190846
2 India New Delhi 1303171035
3 Brazil Brasilia 207847528
df.iloc([0], [0]) --> 'Belgium' |
s.iloc[0] | Selection by position (0th position
on row and column)
df.loc([0], ['Country']) -->
'Belgium'
df.ix[2] -->
Country Brazil
Capital Brasilia
Population 207847528
df.ix[1, 'Capital'] --> 'New Delhi'