I am reading one file having 2 columns.
1 : issue
2 is timestamp
timestamp column : 2020, 1, 15, 2, 32, 40, 113000
How to convert to Datetime format?
I am reading one file having 2 columns.
1 : issue
2 is timestamp
timestamp column : 2020, 1, 15, 2, 32, 40, 113000
How to convert to Datetime format?
Based on what you wrote I think you want
pd.to_datetime(df['timestamp'], format='%Y,%m,%d,%H,%M,%S')
0 2020-01-15 02:32:40
Name: timestamp, dtype: datetime64[ns]
This question seem to already have an answer here:
Convert Pandas Column to DateTime
You can pass any string format to pd.to_datetime, so in your case you would use commas.
df = pd.DataFrame({"label": ["label1", "label2"],
"dt":["2020, 1, 15, 2, 32, 40, 113000",
"2020, 1, 16, 2, 32, 40, 113000"]
})
df['dt_2'] = pd.to_datetime(df['dt'], format='%Y, %m, %d, %H, %M, %S, %f')
df.head()
Which will yield
label dt dt_2
0 label1 2020, 1, 15, 2, 32, 40, 113000 2020-01-15 02:32:40.113
1 label2 2020, 1, 16, 2, 32, 40, 113000 2020-01-16 02:32:40.113