SHARE
TWEET

Pandas - date string -> datetime -> float timestamp

furas Jul 25th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2.  
  3. df = pd.DataFrame({'date': ['04.01.2010', '05.01.2010']})
  4.  
  5. df['datetime'] = pd.to_datetime(df['date'], format='%d.%m.%Y')
  6.  
  7. df['nanoseconds'] = df['datetime'].values.astype(pd.np.float64)
  8. df['seconds']     = df['datetime'].values.astype(pd.np.float64) / 1_000_000_000 # or 1000000000 or 10**9
  9. df['seconds_int'] = df['datetime'].values.astype(pd.np.int64) // 1_000_000_000 # or 1000000000 or 10**9
  10.  
  11. print(df)
  12. print('---')
  13. print(df.dtypes)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top