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 remove 
Python :: python rotate list 
Python :: pandas filter dataframe if an elemnt is in alist 
Python :: python mongodb schema 
Python :: muliline comment in pyhton 
Python :: pandas dataframe for loop begin end index 
Python :: Use CSS in PHP Echo with Style Attribute 
Python :: flask api 
Python :: python string generator 
Python :: tkinter maximise window 
Python :: getting input in python 
Python :: install pocketsphinx error 
Python :: subset in python 
Python :: pycharm update python version 
Python :: batch gradient descent 
Python :: how to go to previous directory in os python 
Python :: global variable python 
Python :: Converting Dataframe from list Using a list in the dictionary 
Python :: comment lister les fichiers un dossier avec python 
Python :: new line print python 
Python :: how to python 
Python :: scikit tsne 
Python :: python loop backward 
Python :: how to make a variable global in python 
Python :: python To find the sum of all the elements in a list. 
Python :: take absolute value in python 
Python :: group by list python 
Python :: push notification using python 
Python :: run all python files in a directory in windows 
Python :: python colored text into terminal 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =