Search code examples
pythonpandasdataframedatedate-range

Generate more than one date cells in each date_range


With pandas.date_range one can create time columns for one's dataframe with ease such as

df["Data"] = pd.date_range(start='2020-01-01 00:00', end='2020-01-05 02:00', freq='H')

Which something like this

enter image description here

I wonder if is it possible to use date_range to create, within the range defined (such as the above), 10 entries for each of the time periods. In other words, 10 cells with 2010-01-01 00:00:00, 10 cells with 2010-01-01 01:00:00, and so on.

If not, how should one do that?


Solution

  • Try np.repeat:

    df['Data'] = np.repeat(pd.date_range(start='2020-01-01 00:00', 
                                         end='2020-01-05 02:00', freq='H'), 
                           10)