Home >Backend Development >Python Tutorial >Solution to error when loading excel in python
This article mainly introduces in detail the solution to the error when loading excel in python. It has certain reference value. Interested friends can refer to it
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 error when loading excel:
IndexError: list index out of range
The reason is that there is a problem with the format of PelicanStores.xlsx and there are extra columns that are not displayed.
Open the file PelicanStores.xlsx with excel and copy the content to a new 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 1 Regular 1 39.50 Discover Male
1 2 Promotional 1 102.40 Proprietary Card Female
2 3 3 Regular 1 22.50 Proprietary Card Female
3 4 Promotional 5 100.40 Proprietary Card Female
## 4 5 Regular 2 54.00 MasterCard Female## 5 6 Regular 1 44.50 MasterCard Female
## 6 7 Promotional 2 78. 00 Proprietary Card Female[100 rows x 8 columns]In [55]:The above is the detailed content of Solution to error when loading excel in python. For more information, please follow other related articles on the PHP Chinese website!