0

I have a DataFrame with this format

Index Date       A B
1     01-01-2000 1 1
2     01-03-2000 3 6

which I would like to index by date and fill in the missing date rows to create something like this

Date       A   B
01-01-2000 1   1
01-02-2000 NaN NaN
01-03-2000 3   6

Following this post I have created the below code, but the empty rows are still not being added.

df.set_index('Date', inplace=True)
df = df.reindex(df.index)
taurus
  • 470
  • 7
  • 22

1 Answers1

1

IIUC

df.Date=pd.to_datetime(df.Date)
df.set_index('Date').reindex(pd.date_range('2000-01-01','2000-01-03'))
Out[90]: 
            Index    A    B
2000-01-01    1.0  1.0  1.0
2000-01-02    NaN  NaN  NaN
2000-01-03    2.0  3.0  6.0
BENY
  • 317,841
  • 20
  • 164
  • 234