'How to join text values in dataset by both axis 0 and 1 in group?
I have a dataset:
id f1 f2
1 'a1' 'a2'
1 'b1' 'b2'
1 'c1' 'c2'
1 'd1' 'd2'
I want to create new column text which is join of all text values from f1 and f2 for each id group. desired result is:
id text
1 'a1. a2. b1. b2'
2 'c1. c2. d1. d2'
How to di that?
I tried this:
df['text'] = ['. '.join(i) for i in zip(df['f1'], df['f2'])]
df['text'] = df.groupby(['id'])['text'].transform(lambda x: '. '.join(x))
But Im looking for best solution for large dataset
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
