0

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?

martineau
  • 119,623
  • 25
  • 170
  • 301
KM Prak
  • 127
  • 1
  • 1
  • 6
  • can you show how your dataframe and csv looks – Jeril Feb 06 '20 at 00:38
  • 1
    Does this answer your question? [Convert Pandas Column to DateTime](https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime) – coradek Feb 06 '20 at 00:51

2 Answers2

0

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]
Kenan
  • 13,156
  • 8
  • 43
  • 50
0

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
coradek
  • 507
  • 4
  • 16