Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def num_els(s):
- d=dict(Counter(s))
- if chr(39) in d.keys():
- return d[chr(39)]//2
- else:
- return 0
- def isnyc(x):
- rez=0
- if x<=-50 and x>=-80:
- rez=3
- elif x<-80:
- rez=2
- else:
- rez=1
- return rez
- def add_features(df):
- managers=df['manager_id']
- cnt=Counter(managers)
- d=dict(cnt)
- df['mns_rate']=df['manager_id'].apply(lambda x: d[x])
- df['dow'] = df['created'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').weekday())
- df['is_weekend'] = df['created'].apply(lambda x: 1 if datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').weekday() in (5, 6) else 0)
- #df['is_day'] = df['created'].apply(lambda x: 1 if datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').hour>11 and datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').hour< 20 else 0 )
- df['features_num']=df['features'].apply(lambda x: num_els(x))
- df['photos_num']=df['photos'].apply(lambda x: num_els(x))
- df['pr_per_brooms']=df['price']/(df['bedrooms']+df['bathrooms']+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement