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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -