大熊猫重新采样后的索引长度

时间:2015-12-15 12:34:25

标签: python pandas

我有5个长度相等的列表i0, i1, i2, i3i4,每个列表的数据来自特定的工作日。例如,i0's数据来自星期一数据,i1包含来自星期二的数据等。
现在我根据每周的日期为每个列表添加一个索引,因为那时我将添加这些新的" small"数据框(x1x2x3x4x5)更大的数据框" df"。

我按照以下方式执行此操作:

listweek = ['W-MON','W-TUE','W-WED','W-THU','W-FRI']

for u,v in enumerate(listweek):    
        r = "x{0} = pd.DataFrame(i[{0}]).set_index(df.resample('{1}').index)".format(u,v)    
        exec r

问题出现是因为在做df.resample('{1}').index时,因为这有时会有不同的长度。 例如

len(df.resample('W-MON').index) = 886

len(df.resample('W-TUE').index) = 885

所以这会导致代码中断以下错误:

ValueError: Length mismatch: Expected axis has 886 elements, new values have 885 elements

这样做的正确方法是什么?

(添加原始df的片段)

enter image description here

0 个答案:

没有答案