update. /JL
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -127,3 +127,4 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
*.tcx
|
28325
example_2.xml
Normal file
28325
example_2.xml
Normal file
File diff suppressed because it is too large
Load Diff
20
main.py
20
main.py
@@ -0,0 +1,20 @@
|
||||
import xmltodict
|
||||
import pprint
|
||||
import pandas as pd
|
||||
|
||||
# Open the file and read the contents
|
||||
with open('test_data.tcx', 'r', encoding='utf-8') as file:
|
||||
my_xml = file.read()
|
||||
|
||||
# Use xmltodict to parse and convert the
|
||||
# XML document
|
||||
my_dict = xmltodict.parse(my_xml)
|
||||
|
||||
df = pd.DataFrame.from_dict(my_dict)
|
||||
df.name = "test"
|
||||
|
||||
# Print the dictionary
|
||||
#pprint.pprint(my_dict, indent=2)
|
||||
|
||||
print("DataFrame name: ", df.name)
|
||||
print(df)
|
||||
|
15
my_pandas.py
Normal file
15
my_pandas.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pandas as pd
|
||||
import io
|
||||
|
||||
print("Pandas version: ", pd.__version__)
|
||||
|
||||
def xml2df(xml_file):
|
||||
with open(xml_file, "r") as F:
|
||||
xml_data = F.read()
|
||||
return pd.read_xml(io.StringIO(xml_data), parser="etree", xpath=".//component-class//feature-value")
|
||||
|
||||
if __name__ == "__main__":
|
||||
df = xml2df("test_data.tcx")
|
||||
df.assign(counter = lambda df: df.groupby('.//component/name').cumcount())
|
||||
|
||||
print(df)
|
Reference in New Issue
Block a user