[英]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...).我在 Pandas 数据框中有一个类似上面的数据集,我使用 xlwings 将这些数据写入 Excel 文件,但我不想在左侧的系列索引列(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:如果我打开excel,我会发现:
如果您的数据是 csv 数据,则可以使用此代码。
df = pd.read_csv(fileName_only, index_col='item')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.