-1

I'm using an imported .csv dataset, and I'm trying to get some information about a specific column. I am not entirely sure if I've done the correct thing here, thoughts? The other 17 columns in this list are different weather types such as visibility, pressure, dew point, etc.

weather=df.head(10)
print(weather)
  • Weather will contain the first 10 rows of your df, these rows may or mat not contain the ten most frequent entries. For us to provide assistance, your question should be edited to include a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Jan 26 '23 at 20:30

1 Answers1

0

Don't know exactly what your DataFrame looks like, so I'm using a toy example. The idea is to use groupby on the weather column, count it, and then sort it.

df = pd.DataFrame({'Weather': ['Rainy', 'Cloudy', 'Rainy', 'Sunny', 'Storm', 'Sunny']})

df.groupby('Weather')['Weather'].agg(weather_count = 'count').sort_values('weather_count', ascending = False)
Michael Cao
  • 2,278
  • 1
  • 1
  • 13