[英]Select rows from DataFrame based on value from one of the column
DataFrame named "result" DataFrame命名为“结果”
**I am trying to get rows with the values == 0
from a DataFrame (named " result
" that you see in the image attached). **我正在尝试从DataFrame中获取
values == 0
的行(您在所附图像中看到的名为“ result
”)。 The SQL Query for something like this will be like: SELECT * FROM RESULT WHERE
column_name equal to some_value My DataFrame has 2 columns. 对于类似这样的SQL查询,将类似于:
SELECT * FROM RESULT WHERE
column_name等于some_value我的DataFrame有2列。 the 1st one is i think named ' Index
' and the 2nd one is named ' 0
' (the names are by default -- didn't bother to change) 我认为第一个命名为“
Index
”,第二个命名为“ 0
”(默认情况下名称为-无需更改)
Because the 2nd column is a binary: based on whether the restaurant review (1st column) was positive or negative (1 or 0). 因为第二列是二进制:基于餐厅评论(第一列)是肯定的还是否定的(1或0)。 I want to get only the rows (of the two columns based on the negative reviews).
我只想获取(基于负面评论的两列中的行)。 when I try the code:
df.loc[df['column_name'].isin(some_values)]
or in my case result.loc[result['0'].isin(0)]
当我尝试代码时:
df.loc[df['column_name'].isin(some_values)]
或在我的情况下为df.loc[df['column_name'].isin(some_values)]
result.loc[result['0'].isin(0)]
I get the error: KeyError: '0'
我收到错误:
KeyError: '0'
Can anybody please help? 有人可以帮忙吗? **
**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.