Wiki Python Pandas

Pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.


Setup notebook for pandas + bokeh

import os
import pandas as pd
import numpy as np
from import output_notebook, show

# setup some globals we'll use as base paths
BASE_DIR = os.path.realpath(os.path.join(os.getcwd(), '..'))
DATA_DIR = os.path.join(BASE_DIR, 'data')

# tell bokeh to output graphs in the notebook

# depends on input data, but maybe handy to see untruncated data if you have a lot of columns
pd.options.display.max_columns = 100

# output the computed paths
print('base:', BASE_DIR)
print('data:', DATA_DIR)

Reorder columns in a pandas dataframe

df = df[['this', 'is', 'the', 'new', 'order']]

Construct a DataFrame from a list of dicts

import pandas as pd

ds = []
for user in users:
        'screen_name': user.screen_name,

df = pd.DataFrame(ds)

Create an index afterward

df = df.set_index('screen_name')

See also