I have a data frame containing a number of observations:
date colour orders
2014-10-20 red 7
2014-10-21 red 10
2014-10-20 yellow 3
I would like to re-index the data frame and standardise the dates.
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
I though to order the data frame by colour
and date
, and then try to re-index it.
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
But it returns a new data frame with the right index but all NaN
values.
date colour orders
2014-10-20 NaN NaN
2014-10-21 NaN NaN
2014-10-22 NaN NaN