How do I convert a column to Pandas Timestamps?

Viewed 42

I have a column in my DataFrame with values like '2022-06-03T00:00:00.000Z' and I want to convert these (in place) to pd.Timestamp. I see many answers he on how to convert to np.datetime64 and on how do convert arbitrary columns of DataFrames, but can't figure out how to apply these to covering to pd.Timestamp.

1 Answers

Use from pd.to_datetime method I think this solve your problem Just you need to active utc argument in your method


import pandas as pd
 
lst = {'a':['Geeks', 'For'],'b':['2022-06-03T00:00:00.000Z','2024-03-03T00:00:00.000Z']}
 
df = pd.DataFrame(lst)

df['b']=pd.to_datetime(df['b'],utc=True)

type(df['b'][0])

pandas._libs.tslibs.timestamps.Timestamp
Related