首页 > 编程知识 正文

python打开excel-如何在Python中打开Excel文件?

时间:2023-05-05 17:34:23 阅读:208598 作者:1947

How do I open a file that is an Excel file for reading in Python?

I"ve opened text files, for example, sometextfile.txt with the reading command. How do I do that for an Excel file?

you can use pandas package as well....

When you are working with an excel file with multiple sheets, you can use:

import pandas as pd

xl = pd.ExcelFile(path + filename)

xl.sheet_names

>>> [u"Sheet1", u"Sheet2", u"Sheet3"]

df = xl.parse("Sheet1")

df.head()

df.head() will print first 5 rows of your Excel file

If you"re working with an Excel file with a single sheet, you can simply use:

import pandas as pd

df = pd.read_excel(path + filename)

print df.head()

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。