简体   繁体   中英

Pandas read_excel gives yes no while reading an excel file

Using pandas to read an excel. I know its straightforward, but the dataframe output is just yes and no.

Regarding the excel file, just 11 columns with normal data, single sheet, with sheet name as Sheet1

In [1]: import pandas

In [2]: import pandas as pd
In [3]: data = pd.read_excel('/path/fileName.xlsx')

In [4]: data
Out[4]:
    No
0  Yes

Using Python 3.6.10 (default, May 24 2020, 21:54:41) and IPython 6.5.0.

Things i have already tried:

  1. Copied the data from this given excel to a new excel file and tried reading using read_excel and that worked as expected.
  2. Went through Documentation
  3. Searched web for some solution.

Any help is highly appreciated.

I encountered similar problem when I started importing excel files into Ipython but I was able to fix it after some time.

Try the following:

In [1]: import pandas

In [2]: import pandas as pd

In [3]: df = pd.read_excel(r'/path/fileName.xlsx', sheet_name =0)

df.head()

Make sure you add letter r just like I did above before the data path on your PC.

Second method:

import openpyxl as op
from openpyxl import load_workbook

df = load_workbook(r"path of your dataset in your PC", sheet_name = 0)

df.head()

The above will show what you have in the first worksheet. Repeat same code and change sheet_name = 1, 2, 3,...... to view others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM