首页 > 解决方案 > 按字符串过滤给我空结果

问题描述

我要求您使用任何其他算法或方法来检测单个列上的异常。

按未显示数据的列过滤。

我正在使用以下方法将我的数据框限制为两列

X=pd.read_csv(‘C:/Users/Path/file.csv’, usecols=[“Describe_File”, "numbers"])
Describe_File   numbers
0   This is the start   25
1   Ending is coming    42
2   Middle of the story 525
3   This is the start   65
4   This is the start   25
5   Middle of the story 35
6   This is the start   28
7   This is the start   24
8   Ending is coming    24
9   Ending is coming    35
10  Ending is coming    25
11  Ending is coming    24
12  This is the start   215

现在我想去列 ** Describe_File** ,按字符串过滤这是开始,然后显示我的数字值

为此,我通常使用以下代码,由于某种原因它没有给我任何东西。该字符串存在于我的 csv 文件中

X = X[X.Describe_File == "This is the start"]

标签: pythonpandascsv

解决方案


您可以使用 .str.contains() - 矢量化子字符串搜索,即

df = X[X.Describe_File.str.contains("This is the start", regex=False)]

推荐阅读