简体   繁体   English

如何在 Python 中使用 str.split() 过滤出一行和一列

[英]How to filter out a row and column using str.split() in Python

How do you filter the individual column to itself?您如何将单个列过滤为自身?

在此处输入图片说明

I want to make it from我想从

   0      1     2  
Action Casual Indie
Action Casual  NaN
Action   NaN  Indie
Action   NaN   NaN

into进入

Action Casual  Indie
 True  True    False
 True  False   True
 True  False   False

Your help will be much appreciated!您的帮助将不胜感激!

You can try this:你可以试试这个:

import pandas as pd

df = pd.DataFrame([['Action', 'Casual', 'NaN'], ['Action', 'NaN', 'Indie'], ['Action', 'NaN', 'NaN']], columns=['Action', 'Casual', 'Indie'])

df = df.apply(lambda x: x == x.name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM