Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Last active August 29, 2015 14:27
Show Gist options
  • Save hughdbrown/76f78c7bd1581d696baf to your computer and use it in GitHub Desktop.
Save hughdbrown/76f78c7bd1581d696baf to your computer and use it in GitHub Desktop.
pandas fragments

Dates

date_range

date_series = pd.date_range("start_date", "end_date")

CSV files

df = pd.read_csv("filename.csv", parse_dates=["column1"], index_col=["column2"])

Grouping and aggregation

groupby

aggregation methods

Indexing

index

set_index

reset_index

reindex

Merge, join, and concatenate

merge

join

concatenate

Stack and unstack

Removing columns

pop

y = df.pop('column1')

drop

df.drop(['column1'], axis=1, inplace=True)

Handling NaNs

dropna

Plotting

boxplot

hist

plot

Selecting

eval

query

where

Rename columns

rename

Selected data

head

tail

describe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment