Python程序无法读取Excel工作表?

问题描述 投票:1回答:1

我尝试过javatpoint.com中的这段代码

代码

   # Import the xlrd module    
import xlrd   

# Define the location of the file   
loc = ("C:\\Users\User\\Desktop\\Book1.xlsx")   

# To open the Workbook   
wb = xlrd.open_workbook(loc)   
sheet = wb.sheet_by_index(0)   

# For row 0 and column 0   
sheet.cell_value(0, 0)

我的Excel工作表

Book1.xlsx

预期输出

Name

但是输出是

>Python excel_001.py

>

程序执行没有任何错误

python xlrd
1个回答
1
投票

为什么不尝试将excel工作表读取为python中的Pandas数据框

import pandas as pd
df = pd.read_excel("C:\\Users\User\\Desktop\\Book1.xlsx")
print(df.head())
© www.soinside.com 2019 - 2024. All rights reserved.