Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert unix timestamp to datetime python pandas

In [23]: df.head()
Out[23]: 
         date  price
0  1349720105  12.08
1  1349806505  12.35
2  1349892905  12.15
3  1349979305  12.19
4  1350065705  12.15
In [25]: df['date'] = pd.to_datetime(df['date'],unit='s')

In [26]: df.head()
Out[26]: 
                 date  price
0 2012-10-08 18:15:05  12.08
1 2012-10-09 18:15:05  12.35
2 2012-10-10 18:15:05  12.15
3 2012-10-11 18:15:05  12.19
4 2012-10-12 18:15:05  12.15

In [27]: df.dtypes
Out[27]: 
date     datetime64[ns]
price           float64
dtype: object
Comment

convert pandas datetime to unix

df['date'].astype(np.int64) // 10**9
Comment

pandas datetime to unix timestamp

dates = pd.to_datetime(['2019-01-15 13:30:00'])
(dates - pd.Timestamp("1970-01-01")) // pd.Timedelta('1s')  
# Int64Index([1547559000], dtype='int64')
Comment

PREVIOUS NEXT
Code Example
Python :: python iterate columns 
Python :: django.db.backends.mysql install 
Python :: change background color of tkinter 
Python :: install python 3.6 mac brew 
Python :: datetime one week ago python 
Python :: scikit learn r2 score 
Python :: create new django project 
Python :: polynomial fit in python 
Python :: df shift one column 
Python :: calculate euclidian distance python 
Python :: how to convert kg to g using python 
Python :: flask development mode 
Python :: python fdr correction 
Python :: tkinter window to start maximized 
Python :: Tensorflow not installing error 
Python :: Extract categorical data features 
Python :: selenium current url 
Python :: How to develop a TCP echo server, in Python? 
Python :: summation django queryset 
Python :: get current working directory python 
Python :: opening image in python 
Python :: pandas groupby count unique rows 
Python :: multiple args for pandas apply 
Python :: convert transformation matrix to pose ros 
Python :: python datetime minus days 
Python :: python check if file has content 
Python :: list map lambda python 
Python :: flatten a list of list python 
Python :: How to set "Unnamed: 0" column as the index in a DataFrame 
Python :: how to make a alert box in python 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =