這篇文章主要為大家詳細介紹了python載入excel報錯解決方法,具有一定的參考價值,有興趣的小夥伴們可以參考一下
from pandas import Series, DataFrame
#import pandas as pd
import numpy as np
#import os
import sys
reload(sys)
sys. setdefultencoding('utf-8')
file1=pd.read_excel('F:/dataanalysis/statistics/PelicanStores.xlsx')
Python 載入excel報錯:
# IndexError: list index out of range
原因是PelicanStores.xlsx 的格式有問題,有未顯示的多餘欄位。
用excle開啟檔案PelicanStores.xlsx, 把內容複製到一個新的excel-PelicanStoresnew即可以。
file1=pd.read_excel('F:/dataanalysis/statistics/PelicanStoresnew.xlsx')
file1
Out[54]:
Customer Type of Customer Items Net Sales Method of Payment Gender 0 1 Regular 1 # 39.50 1 #1 2 Promotional 1 102.40 Proprietary Card Female 22.50 Proprietary Card Female
3 4 Promotional 5 100.40 Proprietary Card Female 54.00 MasterCard Female
5 6 ale
6 7 Promotional 2 78.00 Proprietary Card Female 78.00 Proprietary Card Female
[100 rows x 8 columns]
In [55]:
以上是python載入excel報錯解決方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!