Guest User

Untitled

a guest
Jul 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. dic_1 = pd.DataFrame({'name': ['ram','shyam','mohan', 'kalpesh', 'suresh'],
  2. 'Age' : [15,30,40,50,60]})
  3. df_1 = pd.DataFrame(dic_1)
  4. df_1 ['group'] = np.array(np.random.randn(len(df_1['Age'])))
  5. df_1.loc[df_1['Age'] < 20, 'group'] = "below twenty"
  6. df_1.loc[20 <= df_1['Age'] < 30, 'group'] = "twenty to thrity"
  7. df_1.loc[30 <= df_1['Age'] < 40, 'group'] = "thrity to forty"
  8. df_1.loc[df_1['Age'] > 40, 'group'] = "above forty"
  9. print (df_1)
Add Comment
Please, Sign In to add comment