I have a DataFrame with multiple rows. Is there any way in which they can be combined to form one string?
For example:
words
0 I, will, hereby
1
For anyone want to know how to combine multiple rows of strings in dataframe
,
I provide a method that can concatenate strings within a 'window-like' range of near rows as follows:
# add columns based on 'windows-like' rows
df['windows_key_list'] = pd.Series(df['key'].str.cat([df.groupby(['bycol']).shift(-i)['key'] for i in range(1, windows_size)], sep = ' ')
Note:
This can't be reached by groupby
, because we don't mean the same id of rows, just near rows.