简体   繁体   中英

How to skip default index (series column on the left) when writing data from dataframe in pandas into Excel through xlwings?

  item  sales
0   A    100
1   B    200
2   C    300
3   D    230
4   E    470
5   F    168

I have a dataset like above in pandas dataframe, and I wrote those data into an Excel file using xlwings, but I don't want to the series index column on the left (0,1,2,3,4...). How do I only import the table without a number index column?

Well, you didn't share your code.

I used this:

data = [['A',100],['B',200],['C',300],['D',230],['E',470],['F',168]]

df = pd.DataFrame(data,columns=['item','sales'])

wb = xw.Book()  
wb = xw.Book(r'C:\Users\XXXXXXX\Documents\xport.xlsx') 
sht1 = wb.sheets['Hoja1']
sht1.range('A1').options(pd.DataFrame, index=False).value = df

If I open the excel I find this:

在此处输入图片说明

如果您的数据是 csv 数据,则可以使用此代码。

df = pd.read_csv(fileName_only, index_col='item')

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