![](/img/trans.png)
[英]search folder for subfolders containing certain string, exclude lagging values
[英]Exclude rows containing a certain string
我有一個數據集,如下所示:
df.head()
applicationstartdate segment fpd_30 fpd_90 fstpd_30
0 2020-01-01 00:04:10 3a.TBC Payroll with CB 0.0 0.0 0.0
1 2020-01-01 00:04:17 3a.TBC Payroll with CB 0.0 0.0 0.0
2 2020-01-01 00:14:25 1.TBC Payroll with CH (All) 0.0 0.0 0.0
3 2020-01-01 00:31:59 1.TBC Payroll with CH (All) 0.0 0.0 0.0
4 2020-01-01 00:41:49 1.TBC Payroll with CH (All) 0.0 0.0 0.
我想排除“段”列中包含“工資單”一詞的所有行。
我試過了:
df2 = df[~df["segment"].str.contains('Payroll')]
這產生了:
TypeError:一元操作數類型錯誤〜:'float'
幫助將不勝感激。
您的列中可能有 NaN,您可以使用:
df2 = df[~df["segment"].fillna('').str.contains('Payroll')]
或者,如果您還想過濾掉 NaN:
df2 = df[~df["segment"].fillna('Payroll').str.contains('Payroll')]
您可以使用na = True
參數 - 因為您正在否定條件並且您希望NaN
被過濾。
df2 = df[~df['segment'].str.contains('Payroll', na=True)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.