我只想覆盖数据框上的某些列。假设df2是我的数据帧。
下面是我使用的代码。问题是,即使我将其编码为从第80列开始,它也会覆盖其他列和行。
我只希望覆盖列80及其之后的内容,但不要覆盖列80之前的内容。80是索引,而不是名称。
import pandas as pd
import xlsxwriter
df2 = pd.read_excel(r'C:\Users\RUI LEONHART\Google Drive\Shop\STOCK V2.xlsx',
usecols=['XS1','S1','M1','L1','XL1','XXL1'])
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df2.to_excel(writer, sheet_name='Sheet1', startcol=80)
# Get the xlsxwriter objects from the dataframe writer object.
workbook = writer.book
worksheet = writer.sheets['Sheet1']
# Close the Pandas Excel writer and output the Excel file.
writer.save()
我搜索解决方案。最接近的是这个
但仍会覆盖我不想要的列和行。