Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

group_by

Docs

Get the first column of each group:

result = df.groupby('YourColumn', as_index=False).first()

include_groups: whether to include the group keys as the first level of the resulting DataFrame

sort based on some columns

Docs StackOverflow

# method 1
df['sort_val'] = df['a'] * df['b']
df = df.sort_values('sort_val').drop('sort_val', 1)

# method 2
df = df.loc[(df['a'] * df['b']).sort_values().index]

# iloc has minor improvement in performance
df = df.iloc[(df['a']* df['b']).sort_values().index]

Chart visualization

Ref

plots

Ref

Practilcal Ref with Dataste

bar

Docs

Cookbook

Ref

read json

Docs

multi-index

Docs

importing data into dataframes

Docs