Dinesh R
Dinesh R

Reputation: 31

Changing object_type to datetime in pandas

I am new to Pandas can you please help me to convert the object type to datetime.

before it was

index timestamp   
0        ISODate(2016-10-02T07:37:22.584+05:00)   
1        ISODate(2016-10-02T07:37:22.589+05:00)   
2        ISODate(2016-10-02T07:37:22.590+05:00)   
3        ISODate(2016-10-02T07:37:40.668+05:00)

replaced stings by below command :

df['timestamp'].replace(['ISODate','"'],'',regex=True,inplace = True)

Now the df['timestamp'] is .

index    timestamp      
0        (2016-10-02T07:37:22.584+05:00)    
1        (2016-10-02T07:37:22.589+05:00)    
2        (2016-10-02T07:37:22.590+05:00)  
3        (2016-10-02T07:37:40.668+05:00)

Do help me with changing the object_type data to Date and time. any help can be appreciated.

Upvotes: 0

Views: 93

Answers (1)

Joe
Joe

Reputation: 12417

You can try with:

df['timestamp'] = df['timestamp'].str[1:-1]
df['timestamp'] = pd.to_datetime(df['timestamp'] )

Upvotes: 1

Related Questions