Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 作为另一个查询的一部分,在比较dataframe中特定值的值范围时,如何生成布尔值?_Python_Python 3.x_Pandas_Logical Operators - Fatal编程技术网

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]

你应该能够使用或取决于你需要什么。这些函数适合你的用例吗?另外,你能添加一些输入和预期的输出吗?我知道有人找到了一个可行的解决方案,但你仍然可以共享你的程序和数据吗?这些代码看起来很奇怪。