![](/img/trans.png)
[英]How to drop rows of Pandas DataFrame whose value in a certain column is NaN
[英]How to drop Dataframe rows that start with a certain character string in the first column using column index
我正在转置一个没有定义列名的数据框,然后需要从转置表中删除行,其中第一列(索引 0)中的给定行值以“zrx”开头。 我在想这样的事情应该有效,但似乎无法正常工作:
df[~df[0].str.startswitg("zrx")]
输入数据如下所示(无标题):
Index 0 Index 1
zrx456. True
zrx567 false
abc234 True
Gfh123 False
nbv345 True
zrx456 False
zrx668 True
zrx789 True
我的目标是返回此数据框,其中仅包含第 0 列中以 zrx 开头的行。
如果您知道第一列的名称,请使用
df[~df.Artist.str.startswith('zrx')]
如果您不知道第一列的名称,请使用
df[~df.iloc[:,0].str.startswith('zrx')]
输入
Artist Album Point
0 zrxAC1 A 1
1 AC2 B 2
2 zrxAC1 NaN 3
3 AC4 A 4
4 AC5 C 5
输出
Artist Album Point
1 AC2 B 2
3 AC4 A 4
4 AC5 C 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.