Show Menu
Cheatography

test Cheat Sheet (DRAFT) by

Python For Data Science Cheat Sheet

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

Pandas

The Pandas library is built on NumPy and provides easy-t­o-use data structures and data analysis tools for the Python progra­mming language.
Asking For Help
Dropping
>>i­mport pandas as pd
help(p­d.S­eri­es.loc)
>>> s.drop­(['a', 'c'])
Series
Selection
>>> df.dro­p('­Cou­ntry', axis=1)
A one-di­men­sional labeled array a capable of holding any data type
By Position
Sort & Rank
>>> s = pd.Ser­ies([3, -5, 7, 4], index=­['a', 'b', 'c', 'd'])
>>> df.ilo­c[[­0],[0]]
>>> df.sor­t_i­ndex()
 

I/O

Read and Write to CSV
Read and Write to SQL Query or Database Table
>>> pd.rea­d_csv( , header­=None, nrows=5)
>>> from sqlalchemy import create­_engine
>>> df.to_­csv­('m­yDa­taF­ram­e.csv')
>>> engine = create­_en­gin­e('­sql­ite­://­/:m­emo­ry:')
 
>>> pd.rea­d_s­ql(­"­SELECT * FROM my_tab­le;­", engine)
 
>>> pd.rea­d_s­ql_­tab­le(­'my­_ta­ble', engine)
 
>>> pd.rea­d_s­ql_­que­ry(­"­SELECT * FROM my_tab­le;­", engine)