Cheatography
https://cheatography.com
Functions, Loops, Requests, Pandas, CSV, JSON, etc
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Pandas
CSV |
df = pd.read_csv('file.csv') df.to_csv('file.csv', index=False) |
Exce |
df = pd.read_excel('file.csv') df.to_excel('file.csv', index=False) |
JSON |
df = pd.read_json('file.json') df.to_json('file.json', orient='records', lines=True) |
SQL |
from sqlalchemy import create_engine
engine = create_engine('sqlite:///database.db') df = pd.read_sql('table_name', engine) df.to_sql('table_name', engine, if_exists='replace', index=False) |
A pandas DataFrame (df) is similar to a table in a database or an Excel spreadsheet.
|
Strings
R strings (raw) |
path = r"C:\path\to\file" |
F strings (formatted) |
greeting = f"Hello, {name}!" |
str.format() |
"Hello {}".format("World") |
str.split() |
["Hello", "World"] |
|
|
|