Using Apply in Pandas Lambda functions with multiple if statements

后端 未结 4 1590
一生所求
一生所求 2021-02-09 12:08

I\'m trying to infer a classification according to the size of a person in a dataframe like this one:

      Size
1     80000
2     8000000
3     8000000000
...
<         


        
4条回答
  •  终归单人心
    2021-02-09 12:44

    You can use pd.cut function:

    bins = [0, 1000000, 10000000, 50000000, ...]
    labels = ['<1m','1-10m','10-50m', ...]
    
    df['Classification'] = pd.cut(df['Size'], bins=bins, labels=labels)
    

提交回复
热议问题