[英]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.