pd.ExcelWriter (to_excel) save the results to an existing excel file

NetEase cloud the classroom curriculum link address

https://study.163.com/course/courseMain.htm?share=2&shareId=400000000398149&courseId=1006383008&_trace_c_p_k2_=cd6d8636673a4b03b5f77ca55979c1a7

The only remaining single excel spreadsheet easier to use df.to_excel

pd.ExcelWriter save the results to excel file that already exists, and supports multiple sheet table write excel.

Python openpyxl need to install third-party packages to excel more functional programming

Python code as follows

# -*- coding: utf-8 -*-
"""
Created on Sat Nov 30 13:24:28 2019

@author: [email protected]
"""
import numpy as np
import pandas as pd

df1 = pd.DataFrame({"name": ['Alfred', 'Batman', 'Catwoman'],
                   "toy": [np.nan, 'Batmobile', 'Bullwhip'],
                 "born": [pd.NaT, pd.Timestamp("1940-04-25"),
                           pd.NaT]})

df2 = pd.DataFrame({"name": ['Alfred', 'Jim', 'Catwoman'],
                   "toy": [np.nan, 'Batmobile', 'Bullwhip'],
                 "born": ['Greens',pd.Timestamp("1940-04-25"),
                           pd.NaT]})

with pd.ExcelWriter('result.xls') as writer:
    df1.to_excel(writer, sheet_name='sheet1')
    df2.to_excel(writer, sheet_name='sheet2')
    
    
# Remaining single excel spreadsheet easier to use to_excel
df1.to_excel("result.xlsx")

  

 

Micro-channel scan two-dimensional code, free resources to learn more python

 

Guess you like

Origin www.cnblogs.com/webRobot/p/11962183.html