daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. df_read['Months since mydate 2'] = (  pd.to_datetime('15-03-2019') - df_read['mydate'] )
  2.      
  3. import numpy as np
  4. import pandas as pd
  5. import sqlite3
  6. num=int(10e3)
  7. df=pd.DataFrame()
  8. df['month'] = np.random.randint(1,13,num)
  9. df['year'] = np.random.randint(2000,2005,num)
  10. df['mydate'] = pd.to_datetime(df['year'] * 10000 + df['month']* 100 + df['month'], format ='%Y%m%d' )
  11. df.iloc[20:30,2]=np.nan
  12.  
  13. #this works
  14. df['Months since mydate'] = (  pd.to_datetime('15-03-2019') - df['mydate'] )
  15.  
  16. conn=sqlite3.connect("test_sqllite_dates.db")
  17. df.to_sql('mydates',conn, if_exists='replace')
  18. conn.close()
  19.  
  20. conn2=sqlite3.connect("test_sqllite_dates.db")
  21.  
  22. df_read=pd.read_sql('select * from mydates',conn2 )
  23. # this doesn't work
  24. df_read['Months since mydate 2'] = (  pd.to_datetime('15-03-2019') - df_read['mydate'] )
  25. conn2.close()
  26.  
  27. print(df.dtypes)
  28. print(df_read.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