看板 Python 關於我們 聯絡資訊
我先附上code,本人摸索自學中,還望見諒~ import pandas as pd import html5lib import openpyxl import sys import xlwt import numpy table = pd.read_html('file:///C:/T24/Case8/db.html') T0 = table[0].dropna(axis=0) display(T0) T1 = table[1].dropna(axis=0) writer = pd.ExcelWriter('T0103.xlsx') Sh1 = T0.to_excel(writer,'Sheet1') Sh2 = T1.to_excel(writer,'Sheet2') writer.save() 在display(T0)呈現的欄位是 | 0 | 1 | 2 | 3 | 4 0 | Table24 | 43 | 14 | 13 | 1 而不是圖片綠框的欄位名稱 https://i.imgur.com/QDdfTfg.jpg 問題:請問要怎麼顯示且並存入xlsx裡面?我是漏打了甚麼嗎? 我要呈現的display(T0)欄位是 TABLE | TOTAL-NB-TP | NB-TP-EXECUTED | NB-OF-PASS | NB-OF-FAIL TABLE24 | 43 | 14 | 13 | 1 懇請指點一下<(_ _)> -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.224.40.45 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1514991813.A.B38.html ※ 編輯: han999 (36.224.40.45), 01/03/2018 23:23:19
gmccntzx1: 從寫出的結果看來,原始的資料內應該不含你要的header 01/04 10:27
gmccntzx1: 所以,你可以改用複寫的方式去寫進的你要的header 01/04 10:28
gmccntzx1: pd.DataFrame(header).transpose().to_excel(writer, 01/04 10:29
gmccntzx1: index=False, header=False, startrow=0) 01/04 10:29
gmccntzx1: 上述由設定startrow來把第一列的index改成你要的header 01/04 10:31
gmccntzx1: 然後index=False 是為了不寫入第一行的index 01/04 10:33
※ 編輯: han999 (36.224.40.45), 01/04/2018 22:11:54