The code you tried doesn’t make sense.
df_movies = df_movies[df_movies["country"].str.split(",")]
You seek the string that has comma separated values and separates the values in that character. That is, if you receive the string 'a,b,c'
you will build the list ['a', 'b', 'c']
.
After that you try to access the dataframe from that list, which would be basically:
df_movies[['a', 'b', 'c']]
What should it do?
If the idea is to fetch the first value before the comma, you do not need to access again the dataframe. Just define the value mapping logic and apply it to your column:
df_movies['country'] = df_movies['country'].apply(
lambda values: values.split(',')[0]
)
Thus, the column 'country'
shall have only the first name of the list.
That’s exactly what I wanted! Thank you very much
– danimille