新版本的Pandas使用以下界面加载Excel文件:
read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
Run Code Online (Sandbox Code Playgroud)
但是,如果我不知道可用的床单怎么办?
例如,我正在使用以下表格的excel文件
数据1,数据2 ...,数据N,foo,bar
但我不知道N先验.
有没有办法从熊猫的excel文档中获取工作表列表?
我在一个循环中读取150个excel文件,打开它们xlrd.open_workbook(),返回一个Book对象.最后,当我尝试umount卷时,我无法使用,当我查看时lsof,我发现其中6个文件仍处于打开状态:
$ lsof | grep volumename
python2 32349 deeenes mem REG 0,40 138240 181517 /.../150119.xls
python2 32349 deeenes mem REG 0,40 135168 181482 /.../150609.xls
python2 32349 deeenes mem REG 0,40 140800 181495 /.../140828.xls
python2 32349 deeenes 5r REG 0,40 140800 181495 /.../140828.xls
python2 32349 deeenes 6r REG 0,40 135168 181482 /.../150609.xls
python2 32349 deeenes 7r REG 0,40 138240 181517 /.../150119.xls
Run Code Online (Sandbox Code Playgroud)
这是我的函数我用以下内容读取xls文件:( 为了清晰起见而剥离)
import sys
import xlrd
from xlrd.biffh import XLRDError
def read_xls(xls_file, …Run Code Online (Sandbox Code Playgroud) 有没有办法使用 XlsxWriter 按名称获取工作表?
import win32com.client, types, pythoncom, sys, os, string
import xlsxwriter
xlApp = win32com.client.Dispatch("Excel.Application")
for file in os.listdir("C:\Users\\Desktop\Escel"):
if file.endswith(".xlsx"):
fileName = file
books = xlApp.Workbooks.Open(r"C:\\Users\\Desktop\\Escel\\" + str(fileName))
ws = books.sheet_by_name("2015 Data")
#ws = books.Worksheets[0]
ws.Visible = 1
fileName.replace(".xlsx","")
ws.ExportAsFixedFormat(0, r"C:\\Users\\Desktop\\PDF\\" + str(fileName) + str(".pdf"))
books.Close(True, r"C:\\Users\\Desktop\\Escel\\" + str(fileName))
Run Code Online (Sandbox Code Playgroud)