python - Unique Value Index from two fields -
i'm new pandas , python, , use help.
i have code below, want. creates dummy variables unique values in field , indexes them unique combinations of unique values in 2 other fields.
what 1 row each unique combination of fields used index. right multiple rows 'asset subs end dt' = 10/30/2008
, 'reseller csn' = 55008
if dummy variable comes 3 times. rather have 1 row combination of index field values 3 in dummy variable column.
code: df = data df = df.set_index(['asset_subs_end_dt','reseller_csn']) dummies=pd.get_dummies(df['expertise'])
something like:
df.groupby(level=[0, 1]).expertise.count()
when groupby
, same index grouped together. assuming data in expertise
notnull
, new dataframe
returned unique index values , count
per each index. try out yourself, play around results, , see how can combined existing dataframe
final result want.
Comments
Post a Comment