Accessing all the rows with a same particular element from the pandas dataframe

Viewed 17

I have this particular dataset in a CSV file, I want to find out the names of all crops that grow in the summer season. How can I do that?

enter image description here

1 Answers

You can use pandas.DataFrame.loc to return the rows of every crop that grows in the summer.

import pandas as pd
df = pd.read_csv('anvesh.csv')

mask = df['Season']=='Summer'
out= df.loc[mask]

>>> display(out)

enter image description here

And if you need to get a list of all these crops, you can use this :

list(out['Crop'])
['Moong(Green Gram)'] #Output
Related