[英]How to scale all columns except certain ones in pandas dataframe?
[英]Dropping all rows except ones with a certain criteria
我想刪除“文檔編號”列中不包含“PD-19-05-16”或“PD-19-06-01”的所有行。 但在我運行代碼后,它似乎沒有進行任何更改。
關於如何正確執行此操作或更正代碼的任何建議將不勝感激。
我嘗試使用 df.drop 但遇到了很多問題。
df = df.drop(['Document No.'] != ['PD-19-05-16','PD-19-06-01'])
我希望這能工作,但得到 ValueError: Arrays are different lengths: 4533 vs 2
嘗試:
rows_to_keep = ["PD-19-05-16","PD-19-06-01"]
df.loc[df['Document No.'].isin(rows_to_keep)]
#or if you need the inverse
df.loc[~df['Document No.'].isin(rows_to_keep)]
我認為這不是 drop tbf 的正確用法。 我總是發現使用isin
過濾單個列更容易。
~
作為否定運算符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.