0

I want to convert the below data frame into space-separated in python. Like:

0  ['raj', 'kumar']
1  ['kill', 'bill']

To

0  raj kumar
1  kill bill
Golden Lion
  • 3,840
  • 2
  • 26
  • 35
  • 2
    Does [Converting list of strings in pandas column into string](https://stackoverflow.com/questions/60327204/converting-list-of-strings-in-pandas-column-into-string) answer your question? – wwii Jan 25 '22 at 21:47
  • 1
    Also, check the docs, there's a method: https://pandas.pydata.org/docs/reference/api/pandas.Series.str.join.html – Mark Jan 25 '22 at 21:49
  • Somewhat related: [Column of lists, convert list to string as a new column](https://stackoverflow.com/questions/45306988/column-of-lists-convert-list-to-string-as-a-new-column) – wwii Jan 25 '22 at 21:51
  • try using reduce and join to create a string of the list – Golden Lion Jan 25 '22 at 22:21
  • @wwii That seems to be a different problem. OP's data there turned out to be strings that look like lists, not actually lists. – wjandrea Jan 25 '22 at 22:48

1 Answers1

-1

try using reduce for each row in the dataframe

data=[{'value': ['raj', 'kumar']},
{'value':  ['kill', 'bill']}]
df=pd.DataFrame(data)
print(df)
def concatWords(lst):
    return functools.reduce(lambda x,y: x+" "+y,lst)
df["value"]=df["value"].apply(concatWords)
print(df)

output:

value
0  raj kumar
1  kill bill
Golden Lion
  • 3,840
  • 2
  • 26
  • 35