I have a column that contains strings.
JavaScript
x
5
1
Rm
2
0 Rwws,xxALd
3
1 Ras,yySAw
4
2 Bdbbd1dd
5
I want to cumulatively aggregate the string through the y-axis.
This is the desired output.
JavaScript
1
5
1
Rm
2
0 Rwws,xxALd
3
1 Rwws,xxALdRas,yySAw
4
2 Rwws,xxALdRas,yySAwBdbbd1dd
5
Something like this can be achieved using the expanding or cumsum() function, however it appears to work for numeric attributes only.
Advertisement
Answer
JavaScript
1
5
1
col1
2
0 I
3
1 am
4
2 cool
5
a quick idea
JavaScript
1
2
1
df.apply(lambda x: x+',').cumsum().str.strip(',')
2
output:
JavaScript
1
4
1
0 I
2
1 I,am
3
2 I,am,cool
4
or just:
JavaScript
1
2
1
df.cumsum()
2
output:
JavaScript
1
4
1
0 I
2
1 Iam
3
2 Iamcool
4