如何用python 3打开xlsx文件 [英] how to open xlsx file with python 3

查看:53
本文介绍了如何用python 3打开xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 1 张纸的 xlsx 文件.我正在尝试使用 python 3 (xlrd lib) 打开它,但我得到一个空文件!

I have an xlsx file with 1 sheet. I am trying to open it using python 3 (xlrd lib), but I get an empty file!

我使用此代码:

file_errors_location = "C:\\Users\\atheelm\\Documents\\python excel mission\\errors1.xlsx"
workbook_errors = xlrd.open_workbook(file_errors_location)

并且我没有错误,但是当我输入时:

and I have no errors, but when I type:

workbook_errors.nsheets

我得到0",即使文件有一些工作表......当我输入时:

I get "0", even the file has some sheets... when I type:

workbook_errors 

我明白了:

xlrd.book.Book object at 0x2..

有什么帮助吗?谢谢

推荐答案

你可以像使用 pandas.read_csv 一样使用 Pandas pandas.read_excel:

You can use Pandas pandas.read_excel just like pandas.read_csv:

import pandas as pd
file_errors_location = 'C:\\Users\\atheelm\\Documents\\python excel mission\\errors1.xlsx'
df = pd.read_excel(file_errors_location)
print(df)

这篇关于如何用python 3打开xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆