Python 作为另一个查询的一部分,在比较dataframe中特定值的值范围时,如何生成布尔值?
作为更大查询的一部分比较一系列数字时,如何返回布尔值(见下文) 我目前是如何比较数字的:Python 作为另一个查询的一部分,在比较dataframe中特定值的值范围时,如何生成布尔值?,python,python-3.x,pandas,logical-operators,Python,Python 3.x,Pandas,Logical Operators,作为更大查询的一部分比较一系列数字时,如何返回布尔值(见下文) 我目前是如何比较数字的: df.loc[(df.number == 9.0) | (df.number == 10.0)] 返回符合条件的行。如果在这样一个较大的查询中满足条件,如何返回布尔值(粗体不起作用,因为我不知道如何生成布尔值: flag = **df.loc[(df.number == 9.0) | (compiled_dataframe.number == 10.0)]** and \ (df['label'].loc
df.loc[(df.number == 9.0) | (df.number == 10.0)]
返回符合条件的行。如果在这样一个较大的查询中满足条件,如何返回布尔值(粗体不起作用,因为我不知道如何生成布尔值:
flag = **df.loc[(df.number == 9.0) | (compiled_dataframe.number == 10.0)]** and \
(df['label'].loc[1]==' I love everything about the store!' or\
df['label'].loc[1]==' Friendly customer service'\
or df['label'].loc[1] == ' I found what I was looking for')
我觉得你应该把
索引也传给.loc
((df.number == 9.0) | (df.number == 10.0)).loc[1]
你应该能够使用或取决于你需要什么。这些函数适合你的用例吗?另外,你能添加一些输入和预期的输出吗?我知道有人找到了一个可行的解决方案,但你仍然可以共享你的程序和数据吗?这些代码看起来很奇怪。