pandas 写excel,删除不要的列,并对列名进行重命名

import pandas as pd

data = [{"column4":1,"column3":2,"column2":3,"column1":4}]

df = pd.DataFrame(data,columns=['column1','column2','column3'])

df = df.drop(columns=['column1'])

rename = {"column2":"列2","column3":"列3"}

df.rename(columns=rename,inplace=True)

df.to_excel(r'C:\Users\84977\Desktop\haha.xlsx',index=False,sheet_name='ellis')


https://www.statology.org/pandas-rename-columns-with-dictionary/

你可能感兴趣的:(Pandas,Python,pandas,excel)