-1

I have a dataset which looks as follows:

Station Month Year
A Jan 2021
A Feb 2021
A Jan 2021
B Mar 2021
B Mar 2021
C Apr 2021
D Feb 2021

I am looking to write some code which can identify each unique value within a row and tell me how often it occurs. eg. For the month column the code should tell be Jan occurs twice, Feb occurs twice, Mar occurs twice and Apr occurs once. It would output similar for the Station and Year columns.

My code looks like this at present, but is not working as intended:

import pandas as pd

for col in df["Month"]: print((df["Month"])[col].unique())

Niamh
  • 51
  • 5
  • Read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example), and [edit the question](https://stackoverflow.com/help/privileges/edit) to include one. – kotatsuyaki Oct 23 '22 at 13:44
  • This isn't a discussion forum or tutorial. Please take the [tour] and take the time to read [ask] and the other links found on that page – wwii Oct 23 '22 at 14:00

1 Answers1

0

Try value_counts df["Month"].value_counts()

Deepak Tripathi
  • 3,175
  • 1
  • 8
  • 21