Skip to content Skip to sidebar Skip to footer

Count Appearance Of A Value In A Pandas Row

Hey I am currently iterating through a column in pandas. Now i want to handle the case that a value appears only once in that column different than when it appears multiple times.

Solution 1:

As suggested, use Series.value_counts to create a list of country with count == 1 and use boolean indexing with Series.isin to filter:

country_counts = df_path['country'].value_counts()
country_1 = country_counts[country_counts.eq(1)].index

df_path[df_path['country'].isin(country_1)]

[out]

id  country
2   1   Indonesia
6   1   UK

Post a Comment for "Count Appearance Of A Value In A Pandas Row"