yankeefan11
yankeefan11

Reputation: 485

Setting Pandas index to be a given DateTimeindex

I am trying to pull some daily data, and some data is missing. I would like to fill with something (havent decided on 0's, nans or average filling). I can get a df1 that has an index of the form:

print(df1.columns)
DatetimeIndex(['2020-01-06', '2020-01-07', '2020-01-08', '2020-01-09',
               '2020-01-10', '2020-01-13', '2020-01-14', '2020-01-15'],
          dtype='datetime64[ns]', name='Date', freq=None)

Now I try to pull down some df2, that is missing, lets say '2020-01-08'. Is there a way I can assert that df2.index = df1.index, with there being a column for the missing date, but the data (probably just NaNs that can be ffilled).

Upvotes: 0

Views: 33

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

Use, reindex

df2.reindex(df1.index)

Upvotes: 1

Related Questions