I have a panda data frame. One of the columns contains a list. I want that column to be a single string.
For example my list [\'one\',\'two\',\'three\'] should sim
When you cast col
to str
with astype
, you get a string representation of a python list, brackets and all. You do not need to do that, just apply
join
directly:
import pandas as pd
df = pd.DataFrame({
'A': [['a', 'b', 'c'], ['A', 'B', 'C']]
})
# Out[8]:
# A
# 0 [a, b, c]
# 1 [A, B, C]
df['Joined'] = df.A.apply(', '.join)
# A Joined
# 0 [a, b, c] a, b, c
# 1 [A, B, C] A, B, C