python - Turning DataFrameGroupBy.resample hierarchical index into columns -
i have dataset contains individual observations need aggregate @ coarse time intervals, function of several indicator variables @ each time interval. assumed solution here groupby
operation, followed resample:
adult_resampled = adult_data.set_index('culture', drop=false).groupby(['over64','regioneast','pneumo7', 'pneumo13','pneumo23','pneumononpcv','penr','levr', 'erythr','pens','levs','eryths'])['culture'].resample('as', how='count')
the result awkward-looking series massive hierarchical index, perhaps not right approach, need turn hierarchical index columns. way can hack hierarchical index (by pulling out index labels, contents of columns need).
any tips on ought have done instead appreciated!
i've tried new grouper
syntax, not allow me subsequently change hierarchical indices data columns. applying unstack
table:
results in this:
in order dataset useful, in regression model, need index labels indicators in columns.
Comments
Post a Comment