filter a dataframe rows according to two specific columns values in python

Suppose you have a pandas DataFrame df with columns col1, col2, and col3. You can filter the rows of the DataFrame based on the values of col1 and col2 using the following code:

main.py
filtered_df = df[(df['col1'] == value1) & (df['col2'] == value2)]
66 chars
2 lines

where value1 is the desired value of col1 and value2 is the desired value of col2. The & operator combines two conditions to form a logical 'and' statement.

The resulting filtered_df will contain only the rows where col1 equals value1 and col2 equals value2.

gistlibby LogSnag