Search
 
SCRIPT & CODE EXAMPLE
 

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'])
Comment

PREVIOUS NEXT
Code Example
Python :: python RuntimeWarning: overflow encountered in long_scalars 
Python :: pyplot define plotsize 
Python :: how to plot 2 decimal values in axis python 
Python :: matplotlib legend out of plot 
Python :: mysql config not found 
Python :: python name of current file 
Python :: python calc days between dates 
Python :: cv2 hconcat 
Python :: python get current time without milliseconds 
Python :: pandas convert date to string 
Python :: python number to array of digits 
Python :: python dockerfile 
Python :: python count nested keys 
Python :: python for loop jump by 2 
Python :: python get webpage source 
Python :: python exit button 
Python :: sklearn columntransformer 
Python :: random select algo 
Python :: how to create a car game using python 
Python :: tf.squeeze() 
Python :: determinant of a matrix in python 
Python :: argument sequence in python function 
Python :: selenium get current url 
Python :: how to get a list of followers on instagram python 
Python :: loop through groupby pandas 
Python :: stop a function from continuing when a condition is met python 
Python :: plt.xlabel not working 
Python :: no limit row pandas 
Python :: sort list of dictionaries by key python 
Python :: set axis ticks matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =