Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Reversing 2 columns in an excel sheet with one column having a single variable and the other column having a list using python

I have 2 columns in an excel sheet with columns and values below

Asset Ids FADEL Ids
fcb03 12500,12502
f813a 4062
d79ca 16145
fa632 6698
9c7cd 4062, 6698
4d787 18933
5569a 4062,6698
2cd98 16145
5d58d 9965
52b30 12500,12502

I want an excel sheet with the below output

Asset Ids FADEL Ids
fcb03,52b30 12500
fcb03,52b30 12502
f813a,9c7cd,5569a 4062
d79ca,2cd98 16145
fa632,9c7cd,5569a 6698
4d787 18933
5d5bd 9965

I want the answer through a python code. I tried implementing this through pandas dataframe and I am struck at this point.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Assuming df, the input DataFrame, you can split, explode, and groupby.agg:

out = (df
 .assign(**{'FADEL Ids': df['FADEL Ids'].str.split(',')})
 .explode('FADEL Ids')
 .groupby('FADEL Ids', as_index=False)
 ['Asset Ids'].agg(','.join)
)

print(out)

output:

  FADEL Ids          Asset Ids
0      6698              9c7cd
1     12500        fcb03,52b30
2     12502        fcb03,52b30
3     16145        d79ca,2cd98
4     18933              4d787
5      4062  f813a,9c7cd,5569a
6      6698        fa632,5569a
7      9965              5d58d
about 4 years ago · Santiago Trujillo Report

0

We could try with get_dummies with dot

s = df.set_index('Asset Ids')['FADEL Ids'].str.get_dummies(',')
out = s.T.dot(s.index+',').str[:-1].reset_index()
out
Out[130]: 
   index                  0
0  12500        fcb03,52b30
1  12502        fcb03,52b30
2  16145        d79ca,2cd98
3  18933              4d787
4   4062  f813a,9c7cd,5569a
5   6698  fa632,9c7cd,5569a
6   9965              5d58d
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!