Python程序读取excel工作表不起作用?

2024-09-29 21:44:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我从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

>

程序执行时没有任何错误


Tags: ofthe代码importcomlocationopenloc
2条回答

我没有打印它。我加了一份打印声明

# 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   
print(sheet.cell_value(0, 0))

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

import pandas as pd
df = pd.read_excel("C:\\Users\User\\Desktop\\Book1.xlsx")
print(df.head())

相关问题 更多 >

    热门问题