Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

converting string to datetime pandas

df['date_col'] = pd.to_datetime(df['date_col'], format='%Y-%m-%d %H:%M:%S')

%Y - Year as decimal number (2004)
%m - month as zero padded number (03)
%d - Day of the month (16)
%H - Hour in 24 hour format
%M - Minutes (16)
%S - Seconds (03)

For more formats visit - https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

Add other characters to match the exact format of the date
as given in your dataset (':', '-' etc)
Comment

from string to time python dataframe

dfc['Time_of_Sail'] = pd.to_datetime(dfc['Time_of_Sail'],format= '%H:%M:%S' ).dt.time
Comment

pandas convert string to datetime

In [51]:
pd.to_datetime(df['I_DATE'])

Out[51]:
0   2012-03-28 14:15:00
1   2012-03-28 14:17:28
2   2012-03-28 14:50:50
Name: I_DATE, dtype: datetime64[ns]
Comment

PREVIOUS NEXT
Code Example
Python :: combine dataframes 
Python :: python hello world 
Python :: make directory python 
Python :: how to count range in django template 
Python :: get working directory in python 
Python :: python defaultdict example 
Python :: display video in jupyter notebook 
Python :: python read folder 
Python :: python font family list 
Python :: python style console output 
Python :: generate gif py 
Python :: format string to 2 decimal places python 
Python :: how to make a full pyramid in python 
Python :: make lists for each 2 items in a list 
Python :: return max repeated value in list 
Python :: 2d array pytho 
Python :: How to install XGBoost package in python on Windows 
Python :: lock in python 
Python :: error urllib request no attribute 
Python :: rename column pandas 
Python :: count number of zeros in a number python 
Python :: Get List Into String 
Python :: add pip to path 
Python :: python replace all values in a column 
Python :: 1 line if statement python 
Python :: python print version 
Python :: localize timezone python 
Python :: python print class variables 
Python :: plt multiple figures to show 
Python :: select specific rows from dataframe in python 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =