![](/img/trans.png)
[英]How to merge and center two rows based on a column value in Pandas dataframe?
[英]How to merge rows by index value from two different dataframe using Python Pandas
我是 Python Pandas 的新手。 我有兩個數據框,其中包含一些行和列,但兩個數據框上的數據都不相同。 我需要合並兩個具有相同索引值的數據幀,並在第一個數據幀的缺失位置填充第二個數據幀中的數據
DF1
DF2
輸出_DF
Output_DF = pd.concat([DF1, DF2])
預期的輸出應該像 Output_DF 文件一樣,來自 DF2 的所有行值都將與 DF1 索引合並並填充同一索引的缺失位置。
設置索引后,您可以fillna
DF1=DF1.set_index('index')
DF2=DF2.set_index('index')
Output_DF=DF1.fillna(DF2)
您可以嘗試在這種情況下更新數據框。
enter code here
update1_df.set_index('Index',inplace=True)
update2_df.set_index('Index',inplace=True)
update1_df.update(update2_df)
update1_df
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.