Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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 如何添加带有2个参数的查询_Python_Pandas - Fatal编程技术网

Python 如何添加带有2个参数的查询

Python 如何添加带有2个参数的查询,python,pandas,Python,Pandas,我的数据框在联机\u rt InvoiceNo StockCode Description Quantity InvoiceDate UnitPrice CustomerID Country 141 C536379 D Discount -1 12/1/10 9:41 27.50 14527.0 United Kingdom 154 C536383 35004C SET OF 3 COLOURED FLYING DUCKS -1 12/1/10 9

我的数据框在
联机\u rt

InvoiceNo   StockCode   Description Quantity    InvoiceDate UnitPrice   CustomerID  Country
141 C536379 D   Discount    -1  12/1/10 9:41    27.50   14527.0 United Kingdom
154 C536383 35004C  SET OF 3 COLOURED FLYING DUCKS  -1  12/1/10 9:49    4.65    15311.0 United Kingdom
235 C536391 22556   PLASTERS IN TIN CIRCUS PARADE   -12 12/1/10 10:24   1.65    17548.0 United Kingdom
236 C536391 21984   PACK OF 12 PINK PAISLEY TISSUES -24 12/1/10 10:24   0.29    17548.0 United Kingdom
237 C536391 21983   PACK OF 12 BLUE PAISLEY TISSUES -24 12/1/10 10:24   0.29    17548.0 Hong Kong
需要找到
数量
为负数且
国家=香港

在线查询('Quantity<0')

我需要再添加一个参数


online\u rt.query('Quantity<0'和'country=hongkong')
抛出错误

假设
online\u rt
是一个数据帧,您可以使用:

filtered_df = online_rt[(online_rt['Quantity']<0) & (online_rt['country']=='Hong Kong')]
filtered\u df=online\u rt[(online\u rt['Quantity']与
香港'
一起使用:

online_rt = pd.DataFrame({'Quantity':[-1,2,0],
                          'country':['Hong Kong','USA','Hong Kong']})

filtered_df = online_rt.query("Quantity < 0 & country == 'Hong Kong'")
print (filtered_df)
   Quantity    country
0        -1  Hong Kong
就这样做吧

online_rt.query('Quantity < 0 & country == Hong Kong')
online\u rt.query('Quantity<0&country==hongkong')

我们可以在这里使用查询方法吗?
online_rt.query('Quantity < 0 & country == Hong Kong')