I struggle to understand below code. Based on the documentation I read
apply
invokes function partial
on every value in the series df['startdate']
partial
function passes argument dayfirst=False
to date_change
function (I am note sure why partial function is used here) from datetime import timedelta
from functools import partial
df['startdate'].apply(partial(date_change, dayfirst=False))
Data table before and after (looks the same: shape and order)
0 2019-12-17
1 2019-12-18
2 2019-12-19
3 2019-12-20
4 2019-12-21
5 2021-10-28
6 2021-10-29
Are you trying to convert your date string to datetime?
df['startdate2'] = pd.to_datetime(df['startdate'], dayfirst=True)
Output:
# It looks like the same
>>> df
startdate startdate2
0 2019-12-17 2019-12-17
1 2019-12-18 2019-12-18
2 2019-12-19 2019-12-19
3 2019-12-20 2019-12-20
4 2019-12-21 2019-12-21
5 2021-10-28 2021-10-28
6 2021-10-29 2021-10-29
# But in fact, this is not the case
>>> df.dtypes
startdate object
startdate2 datetime64[ns]
dtype: object