My question is similar to this one: Combine two columns of text in dataframe in pandas/python
However, I want to combine multiple columns, some of which are text and some are non-text. Moreover, I would like to do it in a loop, row by row because I need to preprocess the resulting text
I tried:
for i in range(len(df)):
text = df.loc[i, text_cols].apply(lambda x: ' '.join(str(x)))
text_cols
is a parameter.
But it seems the result is not a text but an array of chars...
Update: It seems the following solution works:
text = ''
for col in text_cols:
text += ' ' + str(df.loc[i,col])
I wonder if there is a more fancy solution for it.