'How can I convert a column has multiple values to list

I have a pandas DataFrame with three columns.

df = pd.read_csv('doc.csv')


document    year    Keywords           
     1     2018     Appliance Interaction; Intrusive Load Monitoring; Appliance Identification            
     2     2018      wireless networks; Learning algorithms; operator recommendations           
     3     2019      Natural Language; Crowdsourcing; Natural Language; Sensemaking  

Data:

{'document': [1, 2, 3],
 'year': [2018, 2018, 2019],
 'Keywords': ['Appliance Interaction; Intrusive Load Monitoring; Appliance Identification',
  'wireless networks; Learning algorithms; operator recommendations',
  'Natural Language; Crowdsourcing; Natural Language; Sensemaking']}

What I want to do is to convert the column (Keywords) into a list like following

X = [Appliance Interaction, Intrusive Load Monitoring, Appliance Identification, wireless networks, Learning algorithms, operator recommendations, Natural Language, Crowdsourcing, Natural Language, Sensemaking]

and save this list into a separate CSV file



Solution 1:[1]

You could split on "; " + explode and convert to list:

X = df['Keywords'].str.split('; ').explode().tolist()

Output:

['Appliance Interaction',
 'Intrusive Load Monitoring',
 'Appliance Identification',
 'wireless networks',
 'Learning algorithms',
 'operator recommendations',
 'Natural Language',
 'Crowdsourcing',
 'Natural Language',
 'Sensemaking']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1