0

I have a dataframe generated using pivot table which looks like this

enter image description here

I want to unmerge the column Score column and it should be like below picture , I want to split the column Score in to two columns.

enter image description here

I tried this code but it split into two rows instead of column

final_df = final_df.apply(lambda x: x.str.split(' ').explode())

enter image description here

Krupali Mistry
  • 624
  • 1
  • 9
  • 23
  • Is your dataframe multi-indexed or is that rank just fluff from your IDE? – Jeff Aug 28 '20 at 10:10
  • @Jeff Yes `index=['PhotoID','ID']` – Krupali Mistry Aug 28 '20 at 10:11
  • 1
    If I'm understanding your dataframe's indexing correctly, you currently have a problem with the indexing after the split. For example after you split `df['Score'][1]`, your two new columns are both still indexed by `df['Score'][1]` – Jeff Aug 28 '20 at 10:18
  • Perhaps this is what you want? https://stackoverflow.com/questions/35491274/pandas-split-column-of-lists-into-multiple-columns – Jeff Aug 28 '20 at 10:26
  • @Jeff I got result using `df['Score'][1]` but the names are changed I want in the same format as shown above – Krupali Mistry Aug 28 '20 at 10:51
  • Please provide a [mcve]. Also, please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors, https://idownvotedbecau.se/imageofcode, https://idownvotedbecau.se/imageofanexception/. – AMC Aug 28 '20 at 10:59

0 Answers0