How to filter pandas dataframe

To filter a Pandas DataFrame based on the values in a column, you can use the DataFrame.loc method, which allows you to select rows based on labels or boolean conditions.

For example, to filter a DataFrame df based on the values in the name column, you can use the following code:

df.loc[df['name'] == 'Name you want to filter']

This will return a new DataFrame containing only the rows where the value in the name column is equal to the specified name.

You can also use other boolean operators, such as >, <, >=, <=, and !=, to create more complex filters. For example, to filter students whose names start with the letter “A”, you can use the following code:

df.loc[df['name'].str.startswith('A')]

You can also use the | (or) and & (and) operators to create filters that combine multiple conditions. For example, to filter students whose names start with the letter “A” and have marks greater than 80, you can use the following code:

df.loc[(df['name'].str.startswith('A')) & (df['marks'] > 80)]

I hope this helps! Let me know if you have any questions or need further assistance.