I can convert string column to datetime column;
pd.to_datetime(data['Document Date'])
.
But how to convert datetime to string back again?
Asked
Active
Viewed 1,673 times
-3

Ratha
- 9,434
- 17
- 85
- 163
-
`data['Document Date'] = data['Document Date'].astype(str)` – moys Oct 04 '19 at 06:34
-
2Possible duplicate of [datetime to string with series in python pandas](https://stackoverflow.com/questions/30132282/datetime-to-string-with-series-in-python-pandas) – henrywongkk Oct 04 '19 at 06:34
-
`df["datetime_col"].dt.strftime('%Y-%m-%d')` – Pyd Oct 04 '19 at 06:36
1 Answers
0
data['Document Date'] = data.apply(lambda x: str(x))
should work.
If your string was formatted in a different way than the default representation of a date in pandas, then you won't be able to convert back to the original string format: that data is lost in the conversion. If this is the case, I recommend you simply create a new column that stores the converted datetime, alongside the existing string column.

Varun Tandon
- 51
- 6