Create new data frames from existing data frame based on unique column values
import pandas as pd
df = pd.DataFrame({
"company_id": ["AA", "AB", "AA", "CD", "AB"],
"company_score": [.07, .08, .06, .0003, .09],
"company_region": ["NW", "NE", "NW", "NW", "NE"]})
# Approach 1
dict_of_companies = {k: v for k, v in df.groupby('company_id')}
# Approach 2
dict_of_companies = dict(tuple(df.groupby("company_id")))
import pprint
pprint.pprint(dict_of_companies)