0

I have the following df:

import pandas as pd
data = pd.DataFrame(
    {'IP_ADDR':['1.1.1.1','1.1.1.2','1.1.1.1','1.1.1.2','1.1.1.3'],
    'Vlan':['TEst', 'Prod', 'Win', 'Linux', 'AIX'],}
    )
print(data)

   IP_ADDR   Vlan
0  1.1.1.1   TEst
1  1.1.1.2   Prod
2  1.1.1.1    Win
3  1.1.1.2  Linux
4  1.1.1.3    AIX

I'm trying to find for each IP addr in column IP_ADDR the matching vlan in the Vlan column. (if the same ip is found more than once in column IP_ADDR then add the new value from column VLan to the existing values for that ip) The expected output should be:

   IP_ADDR   Vlan
0  1.1.1.1   TEst,Win
1  1.1.1.2   Prod, Linux
2  1.1.1.3    AIX

Any ideas guys? Thank you!

bogdann
  • 39
  • 1
  • 8
  • Does this answer your question? [How to implode(reverse of pandas explode) based on a column](https://stackoverflow.com/questions/64235312/how-to-implodereverse-of-pandas-explode-based-on-a-column) – mozway Jul 14 '21 at 12:22
  • 1
    `data.groupby('IP_ADDR', as_index=False)['Vlan'].agg(','.join)` – Henry Ecker Jul 14 '21 at 12:25

0 Answers0