-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandas.py
26 lines (20 loc) · 832 Bytes
/
pandas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd
def split(df, column):
"""
Splits df by groupby on column, yielding pairs of (value, dataframe) per unique column entry.
"""
for _, df_sub in df.groupby(column):
value = df_sub[column].iloc[0]
yield value, df_sub.drop(columns=[column])
def flatten_column_indexes(df, delim='_'):
"""
https://stackoverflow.com/a/45214611/142712
"""
df.columns = [delim.join(tuple(map(str, t))).rstrip(delim) for t in df.columns.values]
def options_for_show(max_columns=None, expand_frame_repr=False, max_rows=60):
"""
Every time I use pandas I have to look this up, so created a convencience function here.
"""
pd.options.display.max_columns = max_columns
pd.options.display.expand_frame_repr = expand_frame_repr
pd.options.display.max_rows = max_rows