簡體   English   中英

如何根據pandas中列的條件刪除一行?

[英]How to drop a row based on the condition of a column in pandas?

  • 我想丟棄含有行'CENTER'2

作品:

BuildingNameContains_center = dframe[dframe[2].str.contains('CENTER')]

輸出作品:

BuildingNameContains_center

產生錯誤:

dframe.drop(BuildingNameContains_center, inplace= True)

KeyError: '[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\\n 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41] not found in axis'

IIUC,而不是子集數據幀然后嘗試刪除行。 只需對原始選擇的倒數進行子集化。

dframe = dframe.loc[~dframe[2].str.contains('CENTER'), :]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM