dataframe unique values in each column
for col in df:
print(df[col].unique())
dataframe unique values in each column
for col in df:
print(df[col].unique())
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us