Advertisement
Kirizhik

Untitled

Nov 1st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. def num_els(s):
  2.     d=dict(Counter(s))
  3.     if chr(39) in d.keys():
  4.        
  5.         return d[chr(39)]//2
  6.     else:
  7.         return 0
  8. def isnyc(x):
  9.     rez=0
  10.     if x<=-50 and x>=-80:
  11.         rez=3
  12.     elif x<-80:
  13.         rez=2
  14.     else:
  15.         rez=1
  16.     return rez
  17. def add_features(df):
  18.     managers=df['manager_id']
  19.     cnt=Counter(managers)
  20.     d=dict(cnt)
  21.     df['mns_rate']=df['manager_id'].apply(lambda x: d[x])
  22.     df['dow'] = df['created'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').weekday())
  23.     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)
  24.     #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 )
  25.     df['features_num']=df['features'].apply(lambda x: num_els(x))
  26.     df['photos_num']=df['photos'].apply(lambda x: num_els(x))
  27.     df['pr_per_brooms']=df['price']/(df['bedrooms']+df['bathrooms']+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement