简体   繁体   中英

How to overcome 'DataFrame' object has no attribute 'excelwriter' in pandas for Python

I have refined an existing xlsx file and want to create three new files based on the content. Successful in getting three new outputs, but not able to write it to new xlsx files.

I tried installing excelwriter but that didn't fixed my problem.

import pandas as pd
import xlsxwriter

xl_file = pd.ExcelFile('C:\\Users\\python_codes\\myfile.xlsx')

dfs = pd.read_excel('myfile.xlsx', sheetname="Sheet1")
test = dfs.drop_duplicates(subset='DetectionId', keep='first', inplace=False)

dfs2 = test[test['list_set_id'] == 1]
print(dfs2)

writer = dfs2.ExcelWriter('newfile.xlxs', engine='xlsxwriter')

df.to_excel(writer, sheet_name='Sheet1')
writer.save()

I want to write new xlsx file with the filtered content from the existing file.

ExcelWriter belongs to the pandas module, not to a DataFrame instance.

writer = dfs2.ExcelWriter should be writer = pd.ExcelWriter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM