Click here to Skip to main content
15,302,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to make excel file with xml. In XML it has items - item - many elements.
I need dongNm, hoNm, etcPurps, area. So I made my code to collect them and my code makes dictionary with "dong", "ho", "Purpose", "Area" key and they are having dongNm, hoNm, etcPurps, area xml values. In XML dong and ho are contained irregularly. So I already made collect them each and sort with dong and ho. But here is where the problem has started. I need dongNm hoNm etcPurps area in one line. I mean if dongNm and hoNm is same, I wanna make it sort in one line, not each line. But item has one dong, ho, etc, area. So Excel was made each line by line.
In conclusion, as you can see it has each line while dong and ho is same.
I need to make it merge in one line if dong and ho is same.
I need your help...
(I can't make key each value of etcPurps cause there are a bunch of values.)

dong ho Purpose area
101 101 aprt 86
101 101 basement 90
101 101 garden 50
101 102 aprt 86
101 102 basement 80

What I want

dong ho Purpose area
101 101 aprt 86 basement 90 garden 50
101 102 aprt 86 basement 80

What I have tried:

import pandas as pd
import os
from IPython.display import display

excel = pd.read_excel(os.getcwd() + '\\1.xlsx')
excel = excel.groupby("호")
excel = pd.merge(excel, excel, on=["동", "호"])
Updated 31-Jan-21 23:46pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900