[英]How to drop Dataframe rows that start with a certain character string in the first column using column index
I am transposing a data frame where I do not have defined column names and then need to drop rows from the transposed table where a given rows value in the first column (index 0) starts with 'zrx'.我正在转置一个没有定义列名的数据框,然后需要从转置表中删除行,其中第一列(索引 0)中的给定行值以“zrx”开头。 I am thinking something like this should work, but can't seem to get it working:
我在想这样的事情应该有效,但似乎无法正常工作:
df[~df[0].str.startswitg("zrx")]
Input data looks like this (no headers):输入数据如下所示(无标题):
Index 0 Index 1
zrx456. True
zrx567 false
abc234 True
Gfh123 False
nbv345 True
zrx456 False
zrx668 True
zrx789 True
My goal is to return this data frame with only the rows that start with zrx in column 0.我的目标是返回此数据框,其中仅包含第 0 列中以 zrx 开头的行。
If you know the name of the first column, use如果您知道第一列的名称,请使用
df[~df.Artist.str.startswith('zrx')]
If you do not know the name of the first column, use如果您不知道第一列的名称,请使用
df[~df.iloc[:,0].str.startswith('zrx')]
input输入
Artist Album Point
0 zrxAC1 A 1
1 AC2 B 2
2 zrxAC1 NaN 3
3 AC4 A 4
4 AC5 C 5
Output输出
Artist Album Point
1 AC2 B 2
3 AC4 A 4
4 AC5 C 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.