我的数据框dfUnderInterpretation中的“状态”列之一具有诸如“确定”,“缺失”和“新建”之类的值。
另一个变量statusInterpretation是一个dict:{'OK':'INFO','New':'WARN','Missing':'ERROR'}
我想根据我的数据框“状态”列中的索引创建一个包含解释值的新列“解释” 。
由于dfUnderInterpretation [' Status ']是一个列表,因此下面的内容当然不起作用。
dfUnderInterpretation ['Interpretation'] = statusInterpretation.get(dfUnderInterpretation ['Status'],无)
您可以使用apply
方法:
dfUnderInterpretation['Status_Desc'] = dfUnderInterpretation['Status'].apply(lambda x: statusInterpretation.get(x))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句