在excel中匹配列下追加数据

2024-05-23 17:17:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用下面提供的答案,所以在xlsx文件中添加数据链接。你知道吗

https://stackoverflow.com/a/38075046/1896796

我正在调用下面的helper方法

append_df_to_excel('test2.xlsx', df_repo, index= False, header = False)

我已经在excel表中添加了列名。但我的所有数据帧都没有相同的列计数或顺序。尽管数据框中的列与excel中的列具有相同的列名。你知道吗

如何将dataframe列添加到excel中的匹配列名下?你知道吗

我的df1

  durable_medical_equipment    pcp  specialist  diagnostic  imaging  generic  formulary_brand  non_preferred_generic  emergency_room  inpatient_facility  medical_deductible_single  medical_deductible_family  maximum_out_of_pocket_limit_single  maximum_out_of_pocket_limit_family plan_name      pdf_name
0                      False  False       False       False    False    False            False                  False           False               False                      False                      False                               False                               False   ABCBCBC  adjnajdn.pdf

df2型

   pcp  specialist  generic  formulary_brand  emergency_room  urgent_care  inpatient_facility  durable_medical_equipment  medical_deductible_single  medical_deductible_family  maximum_out_of_pocket_limit_single  maximum_out_of_pocket_limit_family plan_name      pdf_name
0  True        True    False            False            True         True                True                       True                       True                       True                                True                                True   ABCBCBC  adjnajdn.pdf

在我的excel里,顺序如下-

   durable_medical_equipment    pcp  specialist  diagnostic  imaging  generic  formulary_brand  non_preferred_generic  emergency_room  inpatient_facility  medical_deductible_single  medical_deductible_family  maximum_out_of_pocket_limit_single  maximum_out_of_pocket_limit_family plan_name      pdf_name

Tags: ofnamefalsetruepdfoutexcelfamily
1条回答
网友
1楼 · 发布于 2024-05-23 17:17:34

我不确定,你的数据是什么,但是用python做然后保存到excel呢?你知道吗

假设您有一个现有的excel文件:

Excel.xlsx

以及数据帧文件:

df

然后你可以做:

import pandas as pd
df
excel = pd.read_excel("Excel.xlsx")
frames = [excel, df]
result = pd.concat(frames)
result.to_excel("Excel2.xlsx")

相关问题 更多 >