In [67]:
import pandas as pd

codes = pd.read_csv('muni_codes.csv')
months = pd.read_csv('months.csv')

data = pd.read_csv('net_LandTitles.csv',low_memory=False, encoding='Latin-1', dtype={'MUNI_CODE':str})

data = data.merge(codes, how='left', on='MUNI_CODE')
data = data.merge(months, how='left', on='Month')

data = data[['LINC_NBR','TITLE_NBR','Year','MM','VALUE','Municipality']]
data.sort_values(by=['LINC_NBR','TITLE_NBR','Year','MM'], ascending=True, inplace=True)

print (list(data))


['LINC_NBR', 'TITLE_NBR', 'Year', 'MM', 'VALUE', 'Municipality']

In [ ]:
data['YR_$D'] = data.groupby(['LINC_NBR'])['VALUE'].transform(lambda x: x.diff())
data['YR_%D'] = data.groupby(['LINC_NBR'])['VALUE'].transform(lambda x: x.pct_change())
data['TITLES'] = data.groupby(['Municipality'])['TITLE_NBR'].transform(lambda x: x.count())

In [61]:
data.to_csv('repeat_sales.csv',index=False)