Home > Backend Development > Python Tutorial > Solution to error when loading excel in python

Solution to error when loading excel in python

高洛峰
Release: 2017-03-26 18:17:39
Original
3309 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template