我有一个包含许多观察结果的数据框:
date colour orders
2014-10-20 red 7
2014-10-21 red 10
2014-10-20 yellow 3
我想重新索引数据框并标准化日期。
date colour orders
2014-10-20 red 7
2014-10-21 red 10
2014-10-22 red NaN
2014-10-20 yellow 3
2014-10-21 yellow NaN
2014-10-22 yellow NaN
我想通过colour
and对数据框进行排序date
,然后尝试重新索引它。
index = pd.date_range('20/10/2014', '22/10/2014')
test_df = df.sort(['colour', 'date'], ascending=(True, True))
ts = test_df.reindex(index)
ts
但它返回一个具有正确索引但所有NaN
值的新数据框。
date colour orders
2014-10-20 NaN NaN
2014-10-21 NaN NaN
2014-10-22 NaN NaN