根据if / else创建一个列,其中包含每个条件的字符串值列表

时间:2020-07-11 10:06:18

标签: python pandas if-statement

我正在尝试对UFO目击数据集中的形状组进行编码,以尝试提高模型的准确性,但是我不确定如何将列表用作每次转换的条件。下面是代码。

def shape_group(val):
      if val == ['changed' | 'changing'| 'unknown' |'unspecified' | 'other']: # Uncertain
         return 1
      else:
          return 0

它是简化版本,但是有想法。我最初尝试过:

 if val == ['changed' , 'changing', 'unknown' ,'unspecified' , 'other']

no_nan_df['shape_group'] = no_nan_df['shape'].apply(shape_type)

不返回任何匹配项

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

aarch64-poky-linux-objcopy

这真的很快。在上述情况下,也不需要“其他”。