Python 字符串匹配问题

Python 字符串匹配问题,python,pandas,Python,Pandas,嗨,我正在尝试一个条件,它打印csv文件的某些属性。以下是csv文件: hero_names Agility 3-D Man TRUE A-Bomb FALSE Abe Sapien TRUE Abin Sur FALSE Abomination FALSE Abraxas FALSE Absorbing Man FALSE Adam Monroe FALSE Adam Strange FALSE 我想显示英雄名中的所有项目,其中敏捷性中的行为“真” 我怎么能做到呢?到目

嗨,我正在尝试一个条件,它打印csv文件的某些属性。以下是csv文件:

hero_names  Agility
3-D Man TRUE
A-Bomb  FALSE
Abe Sapien  TRUE
Abin Sur    FALSE
Abomination FALSE
Abraxas FALSE
Absorbing Man   FALSE
Adam Monroe FALSE
Adam Strange    FALSE
我想显示英雄名中的所有项目,其中敏捷性中的行为“真”

我怎么能做到呢?到目前为止,我有以下代码:

import pandas as pd
import os
import numpy as np
import matplotlib.pyplot as plt
import string

super_hero_powers = pd.read_csv(r'super_hero_powers.csv', skiprows=0)

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
true="True"
DFagilityTrue=super_hero_powers[super_hero_powers['Agility'].str.match(true)]

#Return Rows were the conditions are both true
print(DFagilityTrue)

我得到的错误是“str.match”,错误是“raiseAttributeError”(“只能使用带字符串值的.str访问器!”)
AttributeError:只能使用带字符串值的.str访问器!

super\u hero\u powers[super\u hero\u powers['Agility'].eq('TRUE')]
作为字符串值,请使用
.str.contains
,同时将
NaN
设置为
False


super\u hero\u powers[super\u hero\u powers['Agility'].str.contains(r'TRUE',na=False,regex=TRUE)]

尝试了一下,我得到了“未来警告:元素级比较失败;返回标量,但将来将执行元素级比较返回op(a,b)”是的,这是一个基于
pd的警告。但是您是否得到了错误,或者输出是否不正确?我使用的是
pd.\uu版本\uuu==1.1.1
因为'true'是一个布尔值,所以我相信它不会作为字符串工作?我使用的是python 3.8