'int' object is not subscriptable after if statement

后端 未结 3 2041
终归单人心
终归单人心 2021-01-23 02:45

So I have a dataframe:

import pandas as pd

df = pd.DataFrame({\'name\': [\'Jason\', \'Molly\', \'Tina\', \'Jake\', \'Amy\'], 
        \'score\': [1, 3, 4, 5, 2]         


        
3条回答
  •  醉梦人生
    2021-01-23 03:16

    Using pd.cut

    pd.cut(df.score,[0,2,4,np.Inf],labels=['sad','ok','happy'])
    Out[594]: 
    0      sad
    1       ok
    2       ok
    3    happy
    4      sad
    
    #df['yourcol']=pd.cut(df.score,[0,2,4,np.Inf],labels=['sad','ok','happy'])
    

提交回复
热议问题