from sqlalchemy import create_engine
import sys, os
import pandas as pd
from dateutil.parser import parse
def get_query(year,user_id):
    constr = 'mysql+pymysql://{user}:{pwd}@{host}'.format(user=os.environ['MYSQL_USERNAME'],
                                                      pwd=os.environ['MYSQL_PASSWORD'],
                                                      host=os.environ['MYSQL_HOST'])
    con = create_engine(constr)
    df = pd.read_sql('SELECT rev_actor, rev_timestamp FROM fawiki_p.revision where rev_page=2323;', con)
    df=df.astype(int)
    limited_df=df[(df.rev_timestamp<year*(10**10)) & (df.rev_timestamp>(year-1)*(10**10))]
    total_unique_users=len(limited_df.rev_actor.value_counts())
    if user_id in dict(df.rev_actor.value_counts()):
        user_in_history=True
    else:
        user_in_history=False
    total_edits=len(limited_df)
    
year=2019
user_id=10001
get_query(year,user_id)
# https://www.mediawiki.org/wiki/PAWS
parse(str(df.iloc[0,1]))
datetime.datetime(2004, 9, 15, 15, 23, 8)
def find_dff(x):
    print (x)
    return parse(str(x.loc[:,'new']))-parse(str(x.loc[:,'rev_timestamp']))
df['Cl'] - df['Cl'].shift(1)
df['new']=df.iloc[:,1].shift(1)
df=df.fillna(0)
df.new.apply(find_dff)
0.0
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-72-1c73de4b0f2c> in <module>
----> 1 df.new.apply(find_dff)

/srv/paws/lib/python3.6/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
   3589             else:
   3590                 values = self.astype(object).values
-> 3591                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   3592 
   3593         if len(mapped) and isinstance(mapped[0], Series):

pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-71-a050da7f7589> in find_dff(x)
      1 def find_dff(x):
      2     print (x)
----> 3     return parse(str(x.loc[:,'new']))-parse(str(x.loc[:,'rev_timestamp']))

AttributeError: 'float' object has no attribute 'loc'
df=df.fillna(0)