Convert Pandas Dataframe from Column with List to Series

Question:

I have a dataframe column that has a list within it. I need to remove the list so that it is a typical series.

Here is what I have:

import pandas as pd

df = pd.DataFrame({'columnA': [['try', 'go', 'spell'], ['you', 'should', 'to']], 'columnB': [['see', 'it', 'now'], ['why', 'not', 'yes']]})

enter image description here

Here is what I need:

df = pd.DataFrame({'columnA': (['try' " "'go' " " 'spell'], ['you' " "  'should' " "  'to']), 'columnB': (['see' " " 'it' " " 'now'], ['why' " "  'not' " "  'yes'])}

enter image description here

Asked By: JCM

||

Answers:

Based on your question you can use pandas applymap

df.applymap(lambda x: ' '.join(x))

this will generate your output

enter image description here

Answered By: Chinny84
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.