Python Forum
Convert xml to dict and group data and sum totals - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Convert xml to dict and group data and sum totals (/thread-28998.html)



Convert xml to dict and group data and sum totals - kashcode - Aug-13-2020

Hello,

I have xml file with data.
What I need to do. Group data by siteid and merchantname and sum totals from clicks, downloads, newdepositingacc, netrevenue, revsharecommission.
The result I would like to achieve could be something like this:
[{
  'name': 'http://gamblerguy.com (LeoMonaco)',
  'clicks': 'sum clicks totals',
  'downloads': 'sum clicks downloads',
  'newdepositingacc': 'sum newdepositingacctotals',
  'netrevenue': 'sum netrevenue totals',
  'revsharecommission': 'sum revsharecommission totals' 
},
{
  'name': 'casinochimp.com (LeoMonaco)',
  'clicks': 'sum clicks totals',
  'downloads': 'sum clicks downloads',
  'newdepositingacc': 'sum newdepositingacctotals',
  'netrevenue': 'sum netrevenue totals',
  'revsharecommission': 'sum revsharecommission totals'
}]



RE: Convert xml to dict and group data and sum totals - ndc85430 - Aug-13-2020

So, what have you done already and where are you stuck? It would be helpful to see a sample of the XML as well.


RE: Convert xml to dict and group data and sum totals - kashcode - Aug-13-2020

In the evening (UTC +3) I will put how far I am. I've grouped the data but got stuck calculating the totals, don't know how correctly do that. Sample xml you can find here https://www.dropbox.com/s/v9avcxaq12hay5i/ocs.xml?dl=0


RE: Convert xml to dict and group data and sum totals - kashcode - Aug-13-2020

At this moment I have something like this https://repl.it/repls/TubbyWideFactors
list of lists but in each list I want get totals


RE: Convert xml to dict and group data and sum totals - kashcode - Aug-15-2020

I solved my problem https://repl.it/@kashcode/TubbyWideFactors


RE: Convert xml to dict and group data and sum totals - scidam - Aug-16-2020

I suspect that Pandas would be very useful to handle the problem. Pandas comes with rich set of data processing features, e.g. grouping operations, descriptive statistics, i/o operations and much more. If this is not an assignment, I would definitely recommend Pandas to solve such a problem.