In python pandas, there is a Series/dataframe column of str values to combine into one long string:
df = pd.DataFrame({'text' : pd.Series(['Hello', 'world', '!'], index=['a', 'b', 'c'])})
Goal: 'Hello world !'
Thus far methods such as df['text'].apply(lambda x: ' '.join(x))
are only returning the Series.
What is the best way to get to the goal concatenated string?
You can
join
a string on the series directly:Apart from
join
, you could also use pandas string method.str.cat
However,
join()
is much faster.