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