To hang a series, you must use the pd.cut() function , for example:
df['bin'] = pd.cut(df['1'], [0, 50, 100,200]) 0 1 file bin 0 person1 24 age.csv (0, 50] 1 person2 17 age.csv (0, 50] 2 person3 98 age.csv (50, 100] 3 person4 6 age.csv (0, 50] 4 person2 166 Height.csv (100, 200] 5 person3 125 Height.csv (100, 200] 6 person5 172 Height.csv (100, 200]
If you want to name the bins yourself, you can use the labels= argument, for example:
df['bin'] = pd.cut(df['1'], [0, 50, 100,200], labels=['0-50', '50-100', '100-200']) 0 1 file bin 0 person1 24 age.csv 0-50 1 person2 17 age.csv 0-50 2 person3 98 age.csv 50-100 3 person4 6 age.csv 0-50 4 person2 166 Height.csv 100-200 5 person3 125 Height.csv 100-200 6 person5 172 Height.csv 100-200
source share