Open
Description
xref #10347
I'm having trouble understand how exactly reindex is supposed to work in the case of MultiIndex. What I would like is the exact behavior in the Index case where values can be filled or padded according to some level of the MultiIndex. I can't understand what reindex is doing in the MultiIndex case. The below is an example where I would like to interpolate using the prior value a month frame to an hourly frame.
import pandas as pd
d1 = pd.date_range('1/1/2012', '3/1/2012', freq='MS')
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=d1)
dfu = df.unstack()
dfu
Out[12]:
A 2012-01-01 1
2012-02-01 2
2012-03-01 3
B 2012-01-01 4
2012-02-01 5
2012-03-01 6
dtype: int64
d2 = pd.date_range('1/1/2012', '3/31/2012', freq='D')
dfu.reindex(d2, level=1) # What is this supposed to do?
Out[17]:
A 2012-01-01 1
2012-02-01 2
2012-03-01 3
B 2012-01-01 4
2012-02-01 5
2012-03-01 6
dtype: int64
df.reindex(d2, method='pad').unstack() #Ideally something like this, but without the trickery
Out[19]:
A 2012-01-01 1
2012-01-02 1
2012-01-03 1
2012-01-04 1
2012-01-05 1
2012-01-06 1
2012-01-07 1
2012-01-08 1
2012-01-09 1
2012-01-10 1
2012-01-11 1
2012-01-12 1
2012-01-13 1
2012-01-14 1
2012-01-15 1
...
B 2012-03-17 6
2012-03-18 6
2012-03-19 6
2012-03-20 6
2012-03-21 6
2012-03-22 6
2012-03-23 6
2012-03-24 6
2012-03-25 6
2012-03-26 6
2012-03-27 6
2012-03-28 6
2012-03-29 6
2012-03-30 6
2012-03-31 6
Length: 182, dtype: int64