Home > other >  How to create a list of datetime with knowing only the start, the number of iteration and timedelta
How to create a list of datetime with knowing only the start, the number of iteration and timedelta

Time:01-02

I have multiple dataframe with various number of rows. I want to generate differents lists in order to create a column of datetime in every dataframe.

Each row of dataframe correspond to a half-hourly step, and the datetime format is YYYYMMDD HHMMSS 0100

At the end my output should be:

     Date
0    20210101 000000 0100
1    20210101 003000 0100
2    20210101 010000 0100
3    20210101 013000 0100
....

The difference with the problems I encounter on the internet is that I do not enter the end date.

Thanks for your help

CodePudding user response:

import pandas as pd

df = pd.DataFrame([('A', 'Q'), ('Z', 'S'), ('E', 'D'), ('R', 'F')])
df['date'] = pd.date_range(start='2021-01-01', periods=len(df), freq='30min',
                           tz='Europe/Amsterdam').strftime('%Y%m%d %H%M%S%z')
   0  1                  date
0  A  Q  20210101 000000 0100
1  Z  S  20210101 003000 0100
2  E  D  20210101 010000 0100
3  R  F  20210101 013000 0100
  • Related