请看我下面的代码:
import pandas
df = pandas.read_excel('cat.xlsx')
Run Code Online (Sandbox Code Playgroud)
运行后,它给了我以下错误:
Traceback (most recent call last):
File "d:\OneDrive\??\practice.py", line 4, in <module>
df = pandas.read_excel('cat.xlsx')
File "D:\python\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "D:\python\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "D:\python\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "D:\python\lib\site-packages\pandas\io\excel\_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "D:\python\lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "D:\python\lib\site-packages\pandas\io\excel\_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "D:\python\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook
raise …Run Code Online (Sandbox Code Playgroud) 我在python中使用win32.client将.xlsx和.xls文件转换为.csv.当我执行此代码时,它会给出错误.我的代码是:
def convertXLS2CSV(aFile):
'''converts a MS Excel file to csv w/ the same name in the same directory'''
print "------ beginning to convert XLS to CSV ------"
try:
import win32com.client, os
from win32com.client import constants as c
excel = win32com.client.Dispatch('Excel.Application')
fileDir, fileName = os.path.split(aFile)
nameOnly = os.path.splitext(fileName)
newName = nameOnly[0] + ".csv"
outCSV = os.path.join(fileDir, newName)
workbook = excel.Workbooks.Open(aFile)
workbook.SaveAs(outCSV, c.xlCSVMSDOS) # 24 represents xlCSVMSDOS
workbook.Close(False)
excel.Quit()
del excel
print "...Converted " + nameOnly + " to CSV"
except:
print …Run Code Online (Sandbox Code Playgroud) 我在读取由我无法控制的Perl脚本编写的.xls文件时遇到问题.这些文件包含单元格内的一些格式和换行符.
filename = '/home/shared/testfile.xls'
book = xlrd.open_workbook(filename)
sheet = book.sheet_by_index(0)
for rowIndex in xrange(1, sheet.nrows):
row = sheet.row(rowIndex)
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
_locate_stream(Workbook): seen
0 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
20 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
172480= 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 …Run Code Online (Sandbox Code Playgroud) 我想从我的python脚本中获取excelsheet中的特定单元格值.我碰到xlrd,xlwt,xlutils读模块/从excelsheet写入/.
我用hi,hello创建了myfile.xls,如何在第一列的3个单元格中创建.
示例代码: -
import xlrd
workbook = xlrd.open_workbook('myfile.xls')
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = -1
while curr_row < num_rows:
curr_row += 1
row = worksheet.row(curr_row)
print row
Run Code Online (Sandbox Code Playgroud)
输出: -
[text:u'hi']
[text:u'hello']
[text:u'how']
Run Code Online (Sandbox Code Playgroud)
我想从excelsheet读取特定的单元格值,有人可以建议我,如果有办法做到这一点?
我是 Python 新手,有一个问题。我正在尝试使用 pandas 导入 excel 文件,并且我正在使用 VS Code。
import pandas as pd
data = pd.read_excel(r'D:\Python\user.xlsx')
print(data)
Run Code Online (Sandbox Code Playgroud)
我已经安装了xlrd,但是我收到此错误:
Traceback (most recent call last):
File "d:\Python\import-excel.py", line 24, in <module>
data = pd.read_excel(r'D:\Python\user.xlsx')
File "D:\Python\venv\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", …Run Code Online (Sandbox Code Playgroud)