How to add a new column in pandas dataframe based on other column values , for example, Id columns has value and column Value has different values for Id, it needs to be merged as in the output.
df:
# dictionary of lists
data = {'Id':["A", "A", "B", "B","B", "C", "D","E","E", "F", "G","G"],
'Value': ["10$", "2$", "30%", "43%", "12$", "43$", "27$", "40%" ,
"18$",np.nan,np.nan,"89%"]}
df = pd.DataFrame(data)
print(df)
Id Value
0 A 10$
1 A 2$
2 B 30%
3 B 43%
4 B 12$
5 C 43$
6 D 27$
7 E 40%
8 E 18$
9 F nan
10 G nan
11 G 89%
output :
Id Value
0 A 10$, 2$
1 B 30%,43%,12$
3 C 43$
4 D 27$
5 E 40%,18$
6 F nan
7 G 89%