- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
可能是一个简单的答案,所以提前道歉(最少的编码经验)。
我正在尝试从任何列中删除具有特定字符串(经济 7)的任何行,并且一直在尝试离开此线程:
How to drop rows from pandas data frame that contains a particular string in a particular column?
无法让它工作,但在以前的 DataFrame(现在 df = energy)上尝试了此代码,它似乎可以工作,尽管现在出现错误:
no_eco = energy[~energy.apply(lambda series: series.str.contains('Economy 7')).any(axis=1)]
AttributeError: ('只能使用带有字符串值的 .str 访问器,该访问器在 pandas 中使用 np.object_ dtype', '发生在索引现有ProductCodeGas')
有什么建议吗? ps DataFrame 非常大。
谢谢
最佳答案
您只能选择对象列,显然是 select_dtypes
的字符串:
df = energy.select_dtypes(object)
#added regex=False for improve performance like mentioned @jpp, thank you
mask = ~df.apply(lambda series: series.str.contains('Economy 7', regex=False)).any(axis=1)
no_eco = energy[mask]
示例:
energy = pd.DataFrame({
'A':list('abcdef'),
'B':[4,5,4,5,5,4],
'C':[7,8,9,4,2,3],
'D':[1,3,5,7,1,0],
'E':[5,3,6,9,2,4],
'F':list('adabbb')
})
print (energy)
A B C D E F
0 a 4 7 1 5 a
1 b 5 8 3 3 d
2 c 4 9 5 6 a
3 d 5 4 7 9 b
4 e 5 2 1 2 b
5 f 4 3 0 4 b
df = energy.select_dtypes(object)
mask = ~df.apply(lambda series: series.str.contains('d')).any(axis=1)
no_eco = energy[mask]
print (no_eco)
A B C D E F
0 a 4 7 1 5 a
2 c 4 9 5 6 a
4 e 5 2 1 2 b
5 f 4 3 0 4 b
关于python - 删除/删除 pandas DataFrame 中任意列中具有特定字符串的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53063557/
我想要以下内容: void foo( /* something representing a function f */, /* arguments a1, a2, etc. in s
简而言之,我想声明一个这样的特征: trait Test { def test(amount: Int): A[Int] // where A must be a Monad } 这样我就可以
在 GWT 中,如何在 onModuleLoad 方法中插入框架集以及相对嵌套的框架集和框架,以合并许多小程序和其他小部件和 HTML?代码片段是: 公共(public)类 MainEntryPoin
这个问题在这里已经有了答案: How do I best simulate an arbitrary univariate random variate using its probability
我对java相当陌生,并且习惯于枚举本质上只不过是一个命名的整数列表。 现在我正在编写一个实现,其中父类有几个采用枚举值作为参数的方法。枚举将在子类中定义,并且会略有不同。由于枚举基本上看起来像类,所
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
想象一下 6-7 台服务器的设置都完全相同Java 版本“1.6.0_18”OpenJDK 运行时环境 (IcedTea6 1.8) (fedora-36.b18.fc11-i386)OpenJDK
这个问题在这里已经有了答案: What are some uses of template template parameters? (10 个答案) 关闭 4 年前。 我有一个根据策略舍入值的函数
我正在寻找如何在 Java 中给定一个 Async CompletableFutures 列表,以便前 N 个中的任何一个成功完成或失败。除非没有 N 次成功,否则忽略任何失败。 有这方面的例子吗?
我面临的问题是项目已经使用集群编程来分配任务。 if (cluster.isMaster) { // Fork workers. for (var i = 0; i { }); } el
我正在为 Luxology modo(3D 和 VFX 应用程序)编写脚本,该脚本使用 python 作为脚本语言。在我的脚本中的某个位置,我正在读取从其他应用程序输出的文本文件,并从该文本文件的行创
这个问题在这里已经有了答案: Fast arbitrary distribution random sampling (inverse transform sampling) (5 个答案) 关闭
我只是遇到了一个问题,我有一个结构数组,例如 package main import "log" type Planet struct { Name string `json:"
我正在尝试将 class ResponseResult 编码为 json case class ResponseResult (var Code : Int, var
我想将一个矩阵中的一个 block 复制到另一个矩阵的一部分中。要将其与任何类型的 n 维数组一起使用,我需要通过 [] 运算符应用带有偏移量的列表。有办法做到这一点吗? mat_bigger[0:5
我有一个匹配一组数字和字母的正则表达式。但是我希望能够排除任何三个连续的字母。这是为了防止意外形成单词或缩写。 我的表达如下。它还排除了一些类似的字符,如 0、o、O 和 1、i、I、l): ^[2-
根据documentation . 应匹配任何字符,但不匹配重音字符。 mysql> select 'test' regexp 't.st'; +----------------------+ | '
我该如何用 JavaScript 编写这个 if 语句? if(url == "http://www.google.com/" && "*") { ... } * 需要灵活并接受添加到第一个变量上
我知道 cPython 有一个 GIL,因此如果不使用多处理模块,您的脚本就无法在多个内核上运行。但是有什么可以阻止内置功能,例如使用多核进行排序吗?我不了解 cPython 结构,但我想我要问的问题
寻找命令行 gdb 的替代方法来检查 OSX 上的核心转储 - 有没有办法让 Xcode 打开带有调试符号的任意核心转储? 最佳答案 您是否尝试过使用 MachOView 1? 听起来它可能适用于查看
我是一名优秀的程序员,十分优秀!