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
>Solution :
import pandas as pd
from datetime import datetime, timedelta
import pytz
df = pd.DataFrame([('A', 'Q'), ('Z', 'S'), ('E', 'D'), ('R', 'F')])
start = pytz.timezone('Europe/Amsterdam').localize(datetime(2021, 1, 1))
delta = timedelta(minutes=30)
# column of datetime
df['date'] = [start + delta * i for i in range(len(df))]
# column of string
df['date'] = df['date'].apply(lambda x: x.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