Skip to content Skip to sidebar Skip to footer

Resampling A Multi-index Dataframe

I want to resample a DataFrame with a multi-index containing both a datetime column and some other key. The Dataframe looks like: import pandas as pd from StringIO import StringIO

Solution 1:

The example unstacks a non-numerical column 'NAME' which is silently dropped but causes problems during re-stacking. The code below worked for me

print df[['VAR1']].unstack('ID').resample('W-THU').stack('ID')
Params         VAR1
DATE       ID
2013-01-03 A   69.0
           B   69.0
2013-01-10 A   76.0
           B   73.5

Post a Comment for "Resampling A Multi-index Dataframe"