把两个dataframe数据写到同一张excel表的不同sheet

def save_execl1(df1, df2, file_path):
    u"""

    :param df1:
    :param df2: dataframe格式数据
    :param file_path: 想写入的文件路径
    :return:
    """
    writer = pd.ExcelWriter(file_path, engine='openpyxl')
    if os.path.exists(file_path) != True:
        df1.to_excel(writer, sheet_name=u"ali_health_cn", index=None)
    else:
        book = load_workbook(writer.path)
        writer.book = book
    df2.to_excel(writer, sheet_name=u"ali_health_hk", index=False)
    writer.save()
    writer.close()

你可能感兴趣的:(把两个dataframe数据写到同一张excel表的不同sheet)