简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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