Issue
I have a dataframe with two columns as shown below.
location date
paris 6
paris 4
rome 3
paris 5
paris 6
rome 6
paris 4
Now I would like to have counted the different areas in column a, if column b is equal to 6. So the desired result would be:
Paris 2
Rome 1
I am a total noob tbh, the basic idea would be: If column "date" is 6, count the values in column location.
Thx for any help.
Solution
Let's say your dataframe is df
:
df[df['date'] == 6]['location'].value_counts()
Will give you your desired result:
paris 2
rome 1
Name: location, dtype: int64
Answered By - vtasca
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.