python - 按字符串过滤给我空结果
问题描述
我要求您使用任何其他算法或方法来检测单个列上的异常。
按未显示数据的列过滤。
我正在使用以下方法将我的数据框限制为两列
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"]
解决方案
您可以使用 .str.contains() - 矢量化子字符串搜索,即
df = X[X.Describe_File.str.contains("This is the start", regex=False)]
推荐阅读
- sql - 在 SQL Server 中使用替换运行 openquery
- tfs - 如何确定 Azure dev-ops 中代理池脱机的原因
- linux - 如何在 RHEL Linux 服务器上安装 Cargo?
- sql - 如何有选择地应用基于变量的 WHERE IN 子句?
- css - Vue - 在css中获取数据属性值
- c# - 第一次执行的两个等效 LINQ 查询总是运行较慢
- c# - 无法读取或执行 GoogleServicesJson 文件:MainActivity.cs
- java - Spring ApplicationContext加载后,有什么方法可以扫描所有@Component(如带注释的类)
- python - Random.Choice() 正在返回整个字符串
- vue.js - 如何在Vue中从axios返回响应