![](/img/trans.png)
[英]Reading excel with Python Pandas and isolating columns/rows to plot
[英]Isolating pandas columns using boolean logic in python
我正在嘗試獲取滿足以下布爾語句之一或全部的數據框的行:
1) df['colName'] == 0
2) df['colName'] == 1
我已經嘗試過這些,但是沒有一個可行(拋出錯誤):
df = df[df['colName']==0 or df['colName']==1]
df = df[df['colName']==0 | df['colName']==1]
還有其他想法嗎?
您失蹤了()
df = df[(df['colName']==0) | (df['colName']==1)]
這可能會引發復制警告,但仍然可以使用。
如果您不想復制警告,請使用具有以下內容的索引器:
indexer = df[(df['colName']==0) | (df['colName']==1)].index
df = df.loc[indexer,:]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.