Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

.astype datetime

import pandas as pd

# Dataframe example
df = pd.DataFrame({'date':['1995-05-09','1995-05-10','1995-05-11','1995-05-13'],'col_B':[9,7,4,3], 'col_C':[5,1,4,9]})

#This has been answered in the comments where it was noted that the following works:

df.astype({'date': 'datetime64[ns]'})

#In addition, you can set the dtype when reading in the data:

pd.read_csv('path/file.csv', parse_dates=['date'])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #datetime
ADD COMMENT
Topic
Name
6+8 =