Skip to content
Advertisement

How to get an extended dataframe with consecutive datetime rows?

I have a pandas dataframe which looks like this:

JavaScript

The type of column Time is datetime64[ns, pytz.FixedOffset(60)](1), float64(7), int64(1), frequency of this column is 2H. I now want to extend the dataframe by new dates in order to get a dataframe like this one:

JavaScript

Advertisement

Answer

This function should do the work. As parameters it takes in:

  • df dataframe you want to extend, column name you want to extend
  • col column you want to extend from(in your example ‘Time’)
  • periods how many rows you want to generate
  • frequency frequency of the column(in your example ‘2H’)
JavaScript
Advertisement