Last week the below code worked well to convert timestamp to string within a DataFrame:
df.at[i, 'VB12.GMA_DOC']
Timestamp('2022-01-12 00:00:00')
len_df = len(df.index)
df['GMA_DOC'] = ''
for i in range(0,len_df):
df.at[i, 'VB12.GMA_DOC'] = df.at[i, 'VB12.GMA_DOC'].strftime('%Y-%m-%d')
Today, no changes to libraries or other parts of the code, I have the error:
ValueError: cannot set a Timestamp with a non-timestamp str
I noticed that directly from the shell there is no problem:
df.at[i, 'VB12.GMA_DOC'].strftime('%Y-%m-%d')
'2022-01-12'
After some tentatives I solved modifying the code as below:
len_df = len(df.index)
df['GMA_DOC'] = ''
for i in range(0,len_df):
df.at[i, 'GMA_DOC'] = df.at[i, 'VB12.GMA_DOC'].strftime('%Y-%m-%d')
del df['VB12.GMA_DOC']
df['VB12.GMA_DOC'] = df['GMA_DOC']
del df['GMA_DOC']
The problem apparently is the direct assignment of the df_string to the previous df_timestamp column.
Is that normal or do you see a better solution to avoid the error ?