数据帧将行中的值转换为唯一列

Dataframe convert Values in row into a unique column

提问人:KappamanOosh 提问时间:12/8/2020 最后编辑:KappamanOosh 更新时间:12/8/2020 访问量:39

问:

我有一个名为分类列,它显示了不同类型的犯罪结果,即:outcome category

{Investigation complete; no suspect identified, Local resolution, Unable to prosecute suspect, Awaiting court outcome, Formal action is not in the public interest, Offender given penalty notice, Under investigation}\ 从列中,我想提取其中值 =Awaiting court outcome, Under investigation

并在列中出现这些值时创建一个新列,表示 true 或 falseArrestsoutcome

谢谢

Python Pandas 数据帧 编码 布尔逻辑

评论

0赞 Paul Brennan 12/8/2020
stackoverflow.com/help/how-to-ask 是一个很好的指南,可以展示如何提出一个好问题。它通常显示输入数据的示例、为解决问题而编写的一些代码以及所需的结果。有了这个,人们就会了解你想要什么,并能够提供帮助。
0赞 Code Different 12/8/2020
列的数据类型是什么?使用以下结果编辑您的问题outcome categorytype(df.iloc[0, 'outcome category'])
0赞 KappamanOosh 12/8/2020
该列属于分类类型
0赞 Saravanakumar V 12/8/2020
df['outcome'] = df['outcome category'].apply(lambda x : 'Awaiting court outcome' in x or 'Under investigation' in x)

答: 暂无答案