简体   繁体   English

如何在Python中将csv文件名作为工作表名称将“ a.csv”文件添加到现有Excel文件“ b.xlsx”作为新工作表?

[英]How to add “a.csv” file to the existing Excel File “b.xlsx” as a new sheet with csv file name as Sheet name in Python?

Have got a "a.csv" as output in Python and need to add that "a.csv" file to the already existing Excel File "b.xlsx" as a new Sheet to it with sheet name same as the .csv file name. 在Python中有一个“ a.csv”输出,需要将该“ a.csv”文件作为新工作表添加到已经存在的Excel文件“ b.xlsx”中,其工作表名称与.csv文件名相同。 How this could be done in Python? 用Python如何做到这一点?

Thanks is Advance ! 谢谢是前进!

Just read the csv into dataframe and write it into excel . 只需将csv读入dataframe并将其写入excel即可 Refer the below code. 请参考以下代码。

import pandas as pd
writer = pd.ExcelWriter('b.xlsx')
pd.read_csv('a.csv').to_excel(writer,'sheetx')
writer.save()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止csv文件名成为python中的sheet名? - How to prevent the csv file name to be the sheet name in python? 如何使用 python 在现有 csv 文件中创建新工作表并向其中添加一些数据 - how to create a new sheet in existing csv file using python and add some data into that 如何在不提及python中列名的情况下向现有csv文件中添加多个新列? - How to add multiple new columns to existing csv file without mentioning the column name in python? 如何使用熊猫将工作表添加到现有的Excel文件中? - How to add sheet to existing excel file with pandas? 如何使用python3按时间顺序在excel工作表或csv文件中创建新列? - How to create new column in excel sheet or csv file in chronological order using python3? 如何将 XLSX 文件转换为与 XLSX 同名的 CSV? - How to convert XLSX file to CSV with same name as XLSX? 将新工作表添加到现有的excel文件并绘制数据图形 - Add a new sheet to existing excel file and graph the data 如何通过将工作表名称作为参数传递,使用 pandas 库的 read_csv() function 从 CSV 文件读取特定工作表? - how read a specific sheet from a CSV file using read_csv() function of pandas library by passing sheet name as an argument? 如何在现有csv文件的第二列中添加新列(具有标题名称)? - how to add a new column (with a header name) at the 2nd column of the existing csv file? 在.xlsx 文件中创建一个新工作表 - Create a new sheet in .xlsx file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM