How to use Query in pandas
This article mainly introduces how to use Query in pandas. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Query
Query is the filtering query function of pandas, which uses Boolean expressions to query the columns of DataFrame, that is, to filter according to the rules of the columns.
Usage:
Pandas.DataFrame.query (self, expr, inplace = False, * * kwargs)
Parameter function:
Expr: query string to evaluate
Inplace=False: whether the query should modify the data or return the modified copy
Kwargs:dict keyword parameter
First, generate a df:
Values_1 = np.random.randint (10, size=10) values_2 = np.random.randint (10, size=10) years = np.arange (2010) groups = ['group':groups,' year':years, 'value_1':values_1,' value_2':values_2}) df
Filtering queries are easy to use, such as looking up the row records of the column value_1=2016:
Df.query ('year > = 2016')
The above is all the contents of the article "how to use Query in pandas". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!