帮我检查一下代码中的错误import os import pandas as pd import xlsxwriter if 'myXlsxFolder' not in os.listdir(): os.mkdir('myXlsxFolder') os.chdir('myXlsxFolder') books_data = pd.read_cvs('../result.csv',usecols=['name','author','publisher','price','rate','commen','URL'],na_values = 'NULL') titles = books_data['name'] authors = books_data['author'] publisher = books_data['publisher'] prices = books_data['price'] ratings = books_data['ratings'] comments = books_data['comment'] URLs = books_data['URL'] myXlsxFile = xlsxwriter.Workbook('book_info.xlsx') myWorkSheet = myXlsxFile.add_worksheet('豆瓣读书') nums = len(titles) myWorkSheet.write(0,0,'读书标题') myWorkSheet.write(0,1,'图书作者') myWorkSheet.write(0,2,'出版社') myWorkSheet.write(0,3,'图书价格') myWorkSheet.write(0,4,'图书评分') myWorkSheet.write(0,5,'图书简介') myWorkSheet.write(0,6,'资源地址') myWorkSheet.set_column('A:A',20) myWorkSheet.set_column('B:B',20) myWorkSheet.set_column('C:C',30) myWorkSheet.set_column('D:D',20) myWorkSheet.set_column('E:E',10) myWorkSheet.set_column('F:F',100) myWorkSheet.set_column('G:G',50) for i in range(1,nums): myWorkSheet.write(i,0,titles[i]) myWorkSheet.write(i,1, authors[i]) myWorkSheet.write(i,2, publisher[i]) myWorkSheet.write(i,3,prices[i]) myWorkSheet.write(i,4, ratings[i]) myWorkSheet.write(i,5, comments[i]) myWorkSheet.write(i,6, URLs[i]) myXlsxFile.close()
时间: 2023-08-11 22:08:32 浏览: 80
在代码中有两个拼写错误:在导入 pandas 模块时应该是 `read_csv` 而不是 `read_cvs`,而且在导入 pandas 和 xlsxwriter 模块时应该分别写成 `import pandas as pd` 和 `import xlsxwriter`,而不是 `import pandas as pd import xlsxwriter`。此外,变量名 `ratings` 和 `comment` 应该分别改成 `rate` 和 `commen`,以保持和 `usecols` 参数中的列名一致。
以下是修改后的代码:
```
import os
import pandas as pd
import xlsxwriter
if 'myXlsxFolder' not in os.listdir():
os.mkdir('myXlsxFolder')
os.chdir('myXlsxFolder')
books_data = pd.read_csv('../result.csv', usecols=['name','author','publisher','price','rate','commen','URL'], na_values='NULL')
titles = books_data['name']
authors = books_data['author']
publisher = books_data['publisher']
prices = books_data['price']
ratings = books_data['rate']
comments = books_data['commen']
URLs = books_data['URL']
myXlsxFile = xlsxwriter.Workbook('book_info.xlsx')
myWorkSheet = myXlsxFile.add_worksheet('豆瓣读书')
nums = len(titles)
myWorkSheet.write(0,0,'读书标题')
myWorkSheet.write(0,1,'图书作者')
myWorkSheet.write(0,2,'出版社')
myWorkSheet.write(0,3,'图书价格')
myWorkSheet.write(0,4,'图书评分')
myWorkSheet.write(0,5,'图书简介')
myWorkSheet.write(0,6,'资源地址')
myWorkSheet.set_column('A:A',20)
myWorkSheet.set_column('B:B',20)
myWorkSheet.set_column('C:C',30)
myWorkSheet.set_column('D:D',20)
myWorkSheet.set_column('E:E',10)
myWorkSheet.set_column('F:F',100)
myWorkSheet.set_column('G:G',50)
for i in range(nums):
myWorkSheet.write(i+1,0,titles[i])
myWorkSheet.write(i+1,1, authors[i])
myWorkSheet.write(i+1,2, publisher[i])
myWorkSheet.write(i+1,3,prices[i])
myWorkSheet.write(i+1,4, ratings[i])
myWorkSheet.write(i+1,5, comments[i])
myWorkSheet.write(i+1,6, URLs[i])
myXlsxFile.close()
```
阅读全文