Using conditional to generate new column in pandas dataframe

前端 未结 5 1894
-上瘾入骨i
-上瘾入骨i 2020-11-29 02:26

I have a pandas dataframe that looks like this:

   portion  used
0        1   1.0
1        2   0.3
2        3   0.0
3        4   0.8

I\'d

5条回答
  •  情歌与酒
    2020-11-29 02:27

    df['TaxStatus'] = np.where(df.Public == 1, True, np.where(df.Public == 2, False))
    

    This would appear to work, except for the ValueError: either both or neither of x and y should be given

提交回复
热议问题