update. /JL

This commit is contained in:
2024-02-14 18:21:33 +01:00
parent be82c84f9d
commit e879e30678
4 changed files with 28361 additions and 0 deletions

1
.gitignore vendored
View File

@@ -127,3 +127,4 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
*.tcx

28325
example_2.xml Normal file

File diff suppressed because it is too large Load Diff

20
main.py
View File

@@ -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
View 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)