简体   繁体   English

通过xlwings将数据从pandas中的数据帧写入Excel时如何跳过默认索引(左侧的系列列)?

[英]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.

相关问题 从 pandas dataframe 到 excel 与 xlwings? - From pandas dataframe to excel with xlwings? 从两个系列(索引和列)构造 Pandas Dataframe 时如何指定默认值? - How to specify default value when constructing Pandas Dataframe from two series (index and columns)? How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame - How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame 使用xlwings将Pandas Data Frame实时写入Excel文件(.XLSX) - Writing Pandas Data Frame live to Excel file (.XLSX) using xlwings 将具有重复索引的系列数据追加到pandas数据框列 - Appending series data with repeated index to pandas dataframe column 如何从数据框中设置熊猫系列索引并用其他数据填充系列? - How to set pandas series index from a dataframe and fill the series with other data? 从Multi-Index Pandas DataFrame导出/写入Excel选项卡 - Exporting /writing to Excel tabs from a Multi-Index Pandas DataFrame 使用openpyxl在excel工作表中打印python数据帧时如何跳过默认数据帧索引 - How to skip the default data frame index, when printing a python data frame in an excel worksheet, using openpyxl 从多索引熊猫系列创建1列数据框 - Create 1-column dataframe from multi-index pandas series 从系列或字典向数据帧添加一个新列,将我的系列索引和数据帧列映射到键熊猫 python - Add a new column to a dataframe from a Series or dictionary mapping my series index and a dataframe column to key pandas python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM