簡體   English   中英

使用python將excel文件中的一列添加到另一列

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

我有 2 個等於 excel 文件,例外是在其中一個列中的 less 我需要從第一個文件中獲取值並粘貼到另一個我使用 Pandas 來做到這一點,但我做不到

讀取 excel 文件並將它們轉換為變量后,我會這樣做:

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

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

所以我想從df_foglio1 中獲取第一列並將其像df_backup 中的第一列一樣

您可以通過以下方式進行,

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

這可以滿足您的要求。

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

查看更多實施細節: https : //pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM