Arun
Arun

Reputation: 67

Split DataFrame as per series values

I am working on a Netflix dataset where some columns having comma-separated values. I would like a have count of shows released per country but data is like

Image of dataset

How do I split the data and make it countrywide like 1 show releases in 3 countries(Norway, Iceland, United States) then row should come 3 times with a single country in the country column.

show_id country
s5 Norway
s5 Iceland

NOTE: Using pandas

Upvotes: 0

Views: 39

Answers (1)

Nk03
Nk03

Reputation: 14949

You can split the comma-separated string to the list and then apply 'explode' to that column.

df['country'] = df['country'].str.split(',')
df = df.explode('country')
print(df)

Upvotes: 1

Related Questions