我現在正在研究一個數據庫,並且我想從XML到一個Pandas DataFrame,而且我現在已經陷入了很長時間。我不知道如何解決這個問題。Python和Pandas:XML - > DataFrame
j=0
for rows in root.findall('row'):
i=0
for cells in root.findall('cell') in rows:
if i==0:
#Name of the country is on the 0-th tag "cell" of each "row"
country[j]=cells.text
elif i==17:
#Number of students is on the 17-th tag "cell" of each "row"
numberStudent[j]=cells.text
i=i+1
j=j+1
Data=pd.DataFrame({'country': [country], 'number of student': [numberStudent]})
當我試圖讀取數據時,只有一個數據框,其國家值爲0,numberStudent爲0。我不明白什麼是錯的。 我一直在尋找答案已經在這個論壇上,但我仍然堅持。
此外,我不確定我是否正確。我想在每個父標籤「行」中找到第0個和第17個標籤「單元格」。在第二次申報中「in」使用兩次是否正確?
感謝您的幫助,
西里爾