In Python, how to convert this dataframe structure
[['US'], ['CA'], ['GB'], ['FR'], ['AU']]
So that the double nested brackets are removed:
['US', 'CA', 'GB', 'FR', 'AU']
Here's a bit of context. I have a df with customer and country data. I want to count the countries so can find the top5 countries, and them use that as a filter elsewhere.
this gives me the counts
countries = collections.Counter(responses_2021['country'].dropna())
that yields this
[('US', 144), ('CA', 37), ('GB', 15), ('FR', 15), ('AU', 12)]
and this gives me the top 5
countries_top5 = countries.most_common(5)
now I need to transform it into a more simple structure so I can do my filter (here i'm just typing it manually because that's the only way I could move forward lol)
options = ['US', 'CA', 'GB', 'FR', 'AU']
rslt_df = df[df['country'].isin(options)]
SO to get from the this
[('US', 144), ('CA', 37), ('GB', 15), ('FR', 15), ('AU', 12)]
to this
['US', 'CA', 'GB', 'FR', 'AU']
I started by trying to remove the counts
countries_top5_names = np.delete(countries_top5, 1, 1)
but that yields
[['US'], ['CA'], ['GB'], ['FR'], ['AU']]
so now I'm trying to flatten that, but I don't know how.