Issue
I am giving up the SQL solution, and now switching to Pandas. My goal is to merge the integer data as below:
Data input:
ACCT | SOURCES |
---|---|
A | 1 |
A | 2 |
B | 1 |
C | 4 |
expected output:
ACCT | SOURCES |
---|---|
A | 1,2 |
B | 1 |
C | 4 |
Solution
Given:
ACCT SOURCES
0 A 1
1 A 2
2 B 1
3 C 4
Doing:
df.SOURCES = df.SOURCES.astype(str)
df = df.groupby('ACCT', as_index=False)['SOURCES'].agg(','.join)
print(df)
Output:
ACCT SOURCES
0 A 1,2
1 B 1
2 C 4
Answered By - BeRT2me
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.