IN PYTHON:
can you please convert XML given below into dataframe that is in a format so that I can analyze the data .Thanks.
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<Game Date="2017/01/11" Viewers="6740" Place="Newlands
Stadium">
<Team Title="Barcelona">
<Players>
<Player Position="V" Surname="Sam" Name="Sidney"
Nr="16"/>
<Player Position="A" Surname="Cisovsky" Name="Marian"
Nr="17"/>
<Player Position="U" Surname="Verratti" Name="Marco"
Nr="24"/>
<Player Position="A" Surname="Hummels" Name="Mats"
Nr="27"/>
<Player Position="U" Surname="Quintero" Name="Juan"
Nr="33"/>
<Player Position="U" Surname="Díaz" Name="Marcelo"
Nr="37"/>
<Player Position="A" Surname="Criscito" Name="Domenico"
Nr="39"/>
<Player Position="A" Surname="Filip" Name="Lucian"
Nr="55"/>
<Player Position="V" Surname="Saviola" Name="Javier"
Nr="56"/>
<Player Position="A" Surname="Streller" Name="Marco"
Nr="64"/>
<Player Position="U" Surname="Weidenfeller" Name="Roman"
Nr="73"/>
<Player Position="A" Surname="Amelia" Name="Marco"
Nr="75"/>
<Player Position="A" Surname="Sandro" Name="Alex"
Nr="84"/>
<Player Position="U" Surname="Djuricic" Name="Filip"
Nr="89"/>
<Player Position="A" Surname="Varela" Name="Silvestre"
Nr="94"/>
<Player Position="A" Surname="Sauro" Name="Gastón"
Nr="96"/>
</Players>
<Shifts>
<Shift Time="23:34" Nr1="16" Nr2="64"/>
</Shifts>
<Base>
<Player Nr="37"/>
<Player Nr="75"/>
<Player Nr="73"/>
<Player Nr="16"/>
<Player Nr="24"/>
<Player Nr="96"/>
<Player Nr="55"/>
<Player Nr="89"/>
<Player Nr="27"/>
</Base>
<Faouls>
<Faoul Time="41:40" Nr="27"/>
<Faoul Time="56:24" Nr="96"/>
</Faouls>
<Goal>
<VG Time="06:09" Nr="24" Kick="N">
<P Nr="96"/>
<P Nr="55"/>
</VG>
<VG Time="11:07" Nr="73" Kick="N">
<P Nr="24"/>
<P Nr="37"/>
<P Nr="16"/>
</VG>
</Goal>
</Team>
<Team Title="Sochi">
<Players>
<Player Position="A" Surname="Debess" Name="Nils"
Nr="9"/>
<Player Position="A" Surname="Zibens" Name="Vilhelms"
Nr="21"/>
<Player Position="V" Surname="Rausis" Name="Vidmants"
Nr="22"/>
<Player Position="A" Surname="Zibens" Name="Janka"
Nr="25"/>
<Player Position="U" Surname="Palodze" Name="Rihards"
Nr="28"/>
<Player Position="A" Surname="Paraugs" Name="Ciltvairis"
Nr="30"/>
<Player Position="A" Surname="Antena" Name="Bo"
Nr="33"/>
<Player Position="U" Surname="Grants" Name="Linards"
Nr="34"/>
<Player Position="U" Surname="Rokturis" Name="Francis"
Nr="36"/>
<Player Position="A" Surname="Svilpe" Name="Einars"
Nr="39"/>
<Player Position="V" Surname="Zirnis" Name="Anderss"
Nr="41"/>
<Player Position="A" Surname="Kompass" Name="Rolands"
Nr="44"/>
<Player Position="U" Surname="Kabacis" Name="Kens"
Nr="47"/>
</Players>
<Shifts>
<Shift Time="29:24" Nr1="25" Nr2="44"/>
</Shifts>
<Base>
<Player Nr="9"/>
<Player Nr="36"/>
<Player Nr="21"/>
<Player Nr="39"/>
<Player Nr="25"/>
<Player Nr="34"/>
<Player Nr="30"/>
<Player Nr="28"/>
<Player Nr="47"/>
</Base>
<Faouls>
<Faoul Time="50:57" Nr="36"/>
</Faouls>
<Goal>
<VG Time="20:04" Nr="47" Kick="N">
<P Nr="9"/>
<P Nr="25"/>
</VG>
<VG Time="35:38" Nr="34" Kick="N">
<P Nr="30"/>
<P Nr="28"/>
<P Nr="44"/>
</VG>
<VG Time="63:21" Nr="39" Kick="N">
<P Nr="34"/>
</VG>
</Goal>
</Team>
<T Surname="Antamo" Name="Dennis"/>
<T Surname="Prompa" Name="Pedro"/>
<VT Surname="Rausis" Name="Rihards"/>
</Game>
Hi,
Convert xml to dict first, and then dict to data-frame is easy
Code :
import pandas as pd
import xml.etree.ElementTree as ET
import io
# xml data
xml_data = '''
<Game Date="2017/01/11" Viewers="6740" Place="Newlands
Stadium">
<Team Title="Barcelona">
<Players>
<Player Position="V" Surname="Sam" Name="Sidney"
Nr="16"/>
<Player Position="A" Surname="Cisovsky" Name="Marian"
Nr="17"/>
<Player Position="U" Surname="Verratti" Name="Marco"
Nr="24"/>
<Player Position="A" Surname="Hummels" Name="Mats"
Nr="27"/>
<Player Position="U" Surname="Quintero" Name="Juan"
Nr="33"/>
<Player Position="U" Surname="Díaz" Name="Marcelo"
Nr="37"/>
<Player Position="A" Surname="Criscito" Name="Domenico"
Nr="39"/>
<Player Position="A" Surname="Filip" Name="Lucian"
Nr="55"/>
<Player Position="V" Surname="Saviola" Name="Javier"
Nr="56"/>
<Player Position="A" Surname="Streller" Name="Marco"
Nr="64"/>
<Player Position="U" Surname="Weidenfeller" Name="Roman"
Nr="73"/>
<Player Position="A" Surname="Amelia" Name="Marco"
Nr="75"/>
<Player Position="A" Surname="Sandro" Name="Alex"
Nr="84"/>
<Player Position="U" Surname="Djuricic" Name="Filip"
Nr="89"/>
<Player Position="A" Surname="Varela" Name="Silvestre"
Nr="94"/>
<Player Position="A" Surname="Sauro" Name="Gastón"
Nr="96"/>
</Players>
<Shifts>
<Shift Time="23:34" Nr1="16" Nr2="64"/>
</Shifts>
<Base>
<Player Nr="37"/>
<Player Nr="75"/>
<Player Nr="73"/>
<Player Nr="16"/>
<Player Nr="24"/>
<Player Nr="96"/>
<Player Nr="55"/>
<Player Nr="89"/>
<Player Nr="27"/>
</Base>
<Faouls>
<Faoul Time="41:40" Nr="27"/>
<Faoul Time="56:24" Nr="96"/>
</Faouls>
<Goal>
<VG Time="06:09" Nr="24" Kick="N">
<P Nr="96"/>
<P Nr="55"/>
</VG>
<VG Time="11:07" Nr="73" Kick="N">
<P Nr="24"/>
<P Nr="37"/>
<P Nr="16"/>
</VG>
</Goal>
</Team>
<Team Title="Sochi">
<Players>
<Player Position="A" Surname="Debess" Name="Nils"
Nr="9"/>
<Player Position="A" Surname="Zibens" Name="Vilhelms"
Nr="21"/>
<Player Position="V" Surname="Rausis" Name="Vidmants"
Nr="22"/>
<Player Position="A" Surname="Zibens" Name="Janka"
Nr="25"/>
<Player Position="U" Surname="Palodze" Name="Rihards"
Nr="28"/>
<Player Position="A" Surname="Paraugs" Name="Ciltvairis"
Nr="30"/>
<Player Position="A" Surname="Antena" Name="Bo"
Nr="33"/>
<Player Position="U" Surname="Grants" Name="Linards"
Nr="34"/>
<Player Position="U" Surname="Rokturis" Name="Francis"
Nr="36"/>
<Player Position="A" Surname="Svilpe" Name="Einars"
Nr="39"/>
<Player Position="V" Surname="Zirnis" Name="Anderss"
Nr="41"/>
<Player Position="A" Surname="Kompass" Name="Rolands"
Nr="44"/>
<Player Position="U" Surname="Kabacis" Name="Kens"
Nr="47"/>
</Players>
<Shifts>
<Shift Time="29:24" Nr1="25" Nr2="44"/>
</Shifts>
<Base>
<Player Nr="9"/>
<Player Nr="36"/>
<Player Nr="21"/>
<Player Nr="39"/>
<Player Nr="25"/>
<Player Nr="34"/>
<Player Nr="30"/>
<Player Nr="28"/>
<Player Nr="47"/>
</Base>
<Faouls>
<Faoul Time="50:57" Nr="36"/>
</Faouls>
<Goal>
<VG Time="20:04" Nr="47" Kick="N">
<P Nr="9"/>
<P Nr="25"/>
</VG>
<VG Time="35:38" Nr="34" Kick="N">
<P Nr="30"/>
<P Nr="28"/>
<P Nr="44"/>
</VG>
<VG Time="63:21" Nr="39" Kick="N">
<P Nr="34"/>
</VG>
</Goal>
</Team>
<T Surname="Antamo" Name="Dennis"/>
<T Surname="Prompa" Name="Pedro"/>
<VT Surname="Rausis" Name="Rihards"/>
</Game>
'''
# root element
root = ET.fromstring(xml_data)
# get all Game object
game = {
'Team' : [],
'T':[],
'VT':[]
}
# get all teams from root(Game)
teams = root.findall('.//Team')
# loop to all teams
for container in teams:
# create team all dict with empty
team =
{"Players":[],'Shift':[],'BasePlayers':[],'Faoul':[],'Goal':[]}
# get all players from team
players = container.find('.//Players')
# loop to all players in team
for player in players.findall('.//Player'):
# Atrribute .get give the attribute value
playerDetails = {
'Position':player.attrib.get('Position'),
'Surname':player.attrib.get('Surname'),
'Name':player.attrib.get('Name'),
'Nr': player.attrib.get('Nr')
}
team['Players'].append(playerDetails)
shifts = container.find('.//Shifts')
for shift in shifts.findall('.//Shift'):
shiftDetails = {
'Time':player.attrib.get('Time'),
'Nr1':player.attrib.get('Nr1'),
'Nr2':player.attrib.get('Nr2')
}
team['Shift'].append(shiftDetails)
BasePlayers = container.find('.//Base')
for shift in BasePlayers.findall('.//Player'):
BasePlayersDetails = {
'Nr':player.attrib.get('Nr')
}
team['BasePlayers'].append(BasePlayersDetails)
Faouls = container.find('.//Faouls')
for shift in Faouls.findall('.//Faoul'):
FaoulsDetails = {
'Time':player.attrib.get('Time'),
'Nr':player.attrib.get('Nr')
}
team['Faoul'].append(FaoulsDetails)
Goal = container.find('.//Goal')
for goal in Goal.findall('.//VG'):
goalDetails = {
'Time':goal.attrib.get('Time'),
'Nr':goal.attrib.get('Nr'),
'Kick':goal.attrib.get('Kick'),
'P':[]
}
for vg in goal.findall('.//P'):
Pdetails = {
'Nr':vg.attrib.get('Nr')
}
goalDetails['P'].append(Pdetails)
team['Goal'].append(goalDetails)
game['Team'].append(team)
t_s = root.findall('.//T')
for t in t_s:
tdetails ={
'Surname': t.attrib.get('Surname'),
'Name':t.attrib.get('Name')
}
game['T'].append(tdetails)
vt_s = root.findall('.//VT')
for vt in vt_s:
tdetails ={
'Surname': vt.attrib.get('Surname'),
'Name':vt.attrib.get('Name')
}
game['VT'].append(tdetails)
print(game)
df = pd.DataFrame(game['Team'])
print(df)
Images:




Output:
Dict and Dataframe

Type 2 solution:
Directly parse xml to dict using "xmltodict" library.
Code here :
import pandas as pd
import xmltodict
s = """<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<Game Date="2017/01/11" Viewers="6740" Place="Newlands
Stadium">
<Team Title="Barcelona">
<Players>
<Player Position="V" Surname="Sam" Name="Sidney"
Nr="16"/>
<Player Position="A" Surname="Cisovsky" Name="Marian"
Nr="17"/>
<Player Position="U" Surname="Verratti" Name="Marco"
Nr="24"/>
<Player Position="A" Surname="Hummels" Name="Mats"
Nr="27"/>
<Player Position="U" Surname="Quintero" Name="Juan"
Nr="33"/>
<Player Position="U" Surname="Díaz" Name="Marcelo"
Nr="37"/>
<Player Position="A" Surname="Criscito" Name="Domenico"
Nr="39"/>
<Player Position="A" Surname="Filip" Name="Lucian"
Nr="55"/>
<Player Position="V" Surname="Saviola" Name="Javier"
Nr="56"/>
<Player Position="A" Surname="Streller" Name="Marco"
Nr="64"/>
<Player Position="U" Surname="Weidenfeller" Name="Roman"
Nr="73"/>
<Player Position="A" Surname="Amelia" Name="Marco"
Nr="75"/>
<Player Position="A" Surname="Sandro" Name="Alex"
Nr="84"/>
<Player Position="U" Surname="Djuricic" Name="Filip"
Nr="89"/>
<Player Position="A" Surname="Varela" Name="Silvestre"
Nr="94"/>
<Player Position="A" Surname="Sauro" Name="Gastón"
Nr="96"/>
</Players>
<Shifts>
<Shift Time="23:34" Nr1="16" Nr2="64"/>
</Shifts>
<Base>
<Player Nr="37"/>
<Player Nr="75"/>
<Player Nr="73"/>
<Player Nr="16"/>
<Player Nr="24"/>
<Player Nr="96"/>
<Player Nr="55"/>
<Player Nr="89"/>
<Player Nr="27"/>
</Base>
<Faouls>
<Faoul Time="41:40" Nr="27"/>
<Faoul Time="56:24" Nr="96"/>
</Faouls>
<Goal>
<VG Time="06:09" Nr="24" Kick="N">
<P Nr="96"/>
<P Nr="55"/>
</VG>
<VG Time="11:07" Nr="73" Kick="N">
<P Nr="24"/>
<P Nr="37"/>
<P Nr="16"/>
</VG>
</Goal>
</Team>
<Team Title="Sochi">
<Players>
<Player Position="A" Surname="Debess" Name="Nils"
Nr="9"/>
<Player Position="A" Surname="Zibens" Name="Vilhelms"
Nr="21"/>
<Player Position="V" Surname="Rausis" Name="Vidmants"
Nr="22"/>
<Player Position="A" Surname="Zibens" Name="Janka"
Nr="25"/>
<Player Position="U" Surname="Palodze" Name="Rihards"
Nr="28"/>
<Player Position="A" Surname="Paraugs" Name="Ciltvairis"
Nr="30"/>
<Player Position="A" Surname="Antena" Name="Bo"
Nr="33"/>
<Player Position="U" Surname="Grants" Name="Linards"
Nr="34"/>
<Player Position="U" Surname="Rokturis" Name="Francis"
Nr="36"/>
<Player Position="A" Surname="Svilpe" Name="Einars"
Nr="39"/>
<Player Position="V" Surname="Zirnis" Name="Anderss"
Nr="41"/>
<Player Position="A" Surname="Kompass" Name="Rolands"
Nr="44"/>
<Player Position="U" Surname="Kabacis" Name="Kens"
Nr="47"/>
</Players>
<Shifts>
<Shift Time="29:24" Nr1="25" Nr2="44"/>
</Shifts>
<Base>
<Player Nr="9"/>
<Player Nr="36"/>
<Player Nr="21"/>
<Player Nr="39"/>
<Player Nr="25"/>
<Player Nr="34"/>
<Player Nr="30"/>
<Player Nr="28"/>
<Player Nr="47"/>
</Base>
<Faouls>
<Faoul Time="50:57" Nr="36"/>
</Faouls>
<Goal>
<VG Time="20:04" Nr="47" Kick="N">
<P Nr="9"/>
<P Nr="25"/>
</VG>
<VG Time="35:38" Nr="34" Kick="N">
<P Nr="30"/>
<P Nr="28"/>
<P Nr="44"/>
</VG>
<VG Time="63:21" Nr="39" Kick="N">
<P Nr="34"/>
</VG>
</Goal>
</Team>
<T Surname="Antamo" Name="Dennis"/>
<T Surname="Prompa" Name="Pedro"/>
<VT Surname="Rausis" Name="Rihards"/>
</Game>
"""
game = xmltodict.parse(s)
print(game)
df = pd.DataFrame(game)
print(df)
Output for it:

Note: In type one solution you get more flexibility get only required data in the form of required data types. It also increases your coding abilities.
If you have any doubts please comment here.
Hope you got what you want :))
IN PYTHON: can you please convert XML given below into dataframe that is in a format...
== Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...
Studies have shown that exercising can help prevent heart disease. Within reasonable limits, the more you exercise, the less risk you have of suffering from heart disease. One way in which exercise reduces your risk is by reducing serum cholesterol. The more you exercise, the lower your cholesterol concentration. It has recently been shown that the amount of time you spend watching TV, an indicator of a sedentary lifestyle, might be a good predictor of heart disease; that is, the...
In this exercise, you will investigate the relationship between a worker's age and earnings. (Generally, older workers have more job experience, leading to higher productivity and earnings.) The following table contains data for full-time, full-years workers, age 25-34, with a high school diploma or B.A./B.S. as their highest degree. Download the data from the table by clicking the download table icon 0 . A detailed description of the variables used in the data set is available here Use a statistical...
Case: Review Medical Nutrition Therapy: A Case Study Approach - Case 6 Heart Failure with Resulting Cardiac Cachexia. Reviewing chapter 13 of Nutrition Therapy and Pathophysiology will also help you to understand the disease and pathophysiology of this case. 1. Calculate Mrs. Maney's energy and protein requirements. Show your calculations and explain your rationale for the formula you chose for your calculations. (15 points) 2. The MD consults the RDN for nutrition assessment and enteral feeding recommendations. Do you feel...
can you please help me figure out the break even
analysis? (last photo
)
fx =ROUND(420*(2500/4200),2) Total Variable Costs 2$ 4.65 Total Fixed Costs 2$ 858.44 Based on 12 dogs per day. Assume 22 eight-hour work days for kennel attendant. BOARDING Item Variable Costs Item Fixed Costs Kennel attendant 2$ 5.62 Depreciation on kennels 2$ 80.00 Bowls 0.86 Rent 386.90 Towels 0.87 Loan 250.00 Utilities and Insurance 357.14 Depreciation on heating system Cleaning Products: Odoban Cleaning Products: Simple Green 49.40...
Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...
Can someone please tell me what chapters (1-5) these questions
are based on? I have already answered the questions and understand
how to solve the material, but i want to be able to pinpoint where
i can find this info. in the book. I am using Brigham’s
Fundamentals of Financial Management (pictures attached). If it is
hard to read, please let me know. i will post better pictures. i
know the time vale of money stuff already
EDIT: HERE IS...
okay so here is my c++ code and the errors im really stuck on
fixing what i did wrong it seems to be the same repeated
error
our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...
Please use own words. Thank you.
CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions listed below in specific detail. A minimum of 4 pages is required; ensure that you answer all questions completely Case Questions Who are the main players (name and position)? What business (es) and industry or industries is the company in? What are the issues and problems facing the company? (Sort them by importance and urgency.) What are the characteristics of the environment in which...
1. When it comes to financial matters, the views of Aristotle can be stated as: a. usury is nature’s way of helping each other. b. the fact that money is barren makes it the ideal medium of exchange. c. charging interest is immoral because money is not productive. d. when you lend money, it grows more money. e. interest is too high if it can’t be paid back. 2. Since 2008, when the monetary base was about $800 billion,...