Python Pandas: constant date index

I have the following time series data:

EventCount Date 2015-06-23 1 2015-06-25 1 2015-05-29 1 

I need to fill in the data, so the index has continuous dates, for example:

  EventCount Date 2015-06-23 1 2015-06-24 0 2015-06-25 1 2015-06-26 0 2015-06-27 0 2015-06-28 0 2015-05-29 1 

How can i do this?

+1
source share
1 answer

You can use .reindex() .

 # your data # =================================== print(df) EventCount Date 2015-06-23 1 2015-06-25 1 2015-06-29 1 # processing # ============================== df.reindex(pd.date_range(df.index[0], df.index[-1], freq='D')).fillna(0) EventCount 2015-06-23 1 2015-06-24 0 2015-06-25 1 2015-06-26 0 2015-06-27 0 2015-06-28 0 2015-06-29 1 
+5
source

Source: https://habr.com/ru/post/1233070/


All Articles