简体   繁体   中英

Add a column from an excel file to another one with python

I have 2 equals excel file, the exception is on one column in less in one of them I need to grab the value from the first file and paste on the other one I use pandas to do that but I can't do it

After read the excel file and sved them into a variable I do:

df_foglio1 = pd.read_excel(excel_file, sheet_name, header=0)

df_backup = pd.read_excel(backup, sheet_name, header=0)

So I want to grab the first column from df_foglio1 and put it like first column in df_backup

您可以通过以下方式进行,

df_backup['column_name'] = df_foglio1['first_column_name']

This does what you are asking for.

df_foglio1 = pd.read_excel(excel_file, sheet_name, header=0)
df_foglio1['first_column_name'].to_excel('df_backup.xslx')

Check this out for more implementation details: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM