I tried to convert the list obtained by Parsing XML to Pandas DataFrame, but an error occurred when the number of elements differs depending on the XML, so I will describe the remedy.
#List stores different numbers of data depending on XML
Date = []
SerialNumver = []
TrendDate = []
df = pd.DataFrame({'Date': Date,
'SerialNumber': SerialNumber,
'TrendDate': TrendDate})
Error code
ValueError: arrays must all be same length
Even if I count the elements of list, the same number comes out, so it was closed in all directions.
The description of DataFrame has been changed as follows.
#List stores different numbers of data depending on XML
Date = []
SerialNumver = []
TrendDate = []
#Combine list into one
listData = [Date, SerialNumber, TrendDate]
#Convert to DataFrame..T swaps rows and columns
df = pd.DataFrame(listData).T
#Add column name
df.columns = ['Date', 'SerialNumber', 'TrendDate']
I'm not sure what caused it, but now it's error-free.
Recommended Posts