[英]Concat, or merge two dataframe pandas
我這里有兩個數據幀,第一個數據幀的形狀是 (10840, 109),第二個是 (0,112)
我想連接/合並上面的兩個數據框。 我試過df_part_2 = pd.concat([df_revisi_data,df_migrasi_part2],axis=1)
,但結果是 (10840, 221)。 我嘗試了另一種方法df_part_2 = pd.concat([df_revisi_data,df_migrasi_part2],axis=0)
但錯誤上升InvalidIndexError: Reindexing only valid with uniquely valued Index objects
老實說,第一個 dataframe 上的所有列都存在於第二個數據幀上。 然而,結果並沒有達到我的預期。 新的 dataframe 形狀的結果是 (10840,112),其中包含第一個 dataframe 的數據,但列引用了第二個 Z6A8064B5DF4794555500553C47DZ。
第一片 dataframe
No Lead ID* Nama Petani Point Tanggal Pengajuan* Nama PIC Utama* Email PIC Utama* Grading Point* CF0 FUA pov - Status* CF0 FUA pov - Start Date* ... CF10 Verifikasi PKS - Email PIC* CF10 Open Limit - Status* CF10 Open Limit - Start Date* CF10 Open Limit - End Date* CF10 Open Limit - Remarks CF10 Open Limit - Nama PIC* CF10 Open Limit - Email PIC* Review \nby Eng Migrated \nby Eng Note \nby Eng
0 1 5147hvhaau26 AMAN WIJAYA LOMBOK TENGAH 2021-08-01 00:00:00 Ria Arumsari ria.arumsari@efishery.com Grade B APPROVED 2021-08-01 00:00:00 ... fitria.rahma@efishery.com ACTIVE 2021-10-16 00:00:00 2021-10-16 00:00:00 STATUS DETAIL: REMARKS: Fitria Rahma Nur S fitria.rahma@efishery.com TRUE TRUE None
1 2 512bcr75iqp8 SAHMA DAHNIARTI BENGKULU SELATAN 2021-08-01 00:00:00 Fitria Rahma Nur S fitria.rahma@efishery.com Grade A APPROVED 2021-08-01 00:00:00 ... fitria.rahma@efishery.com ACTIVE 2021-08-27 00:00:00 2021-08-27 00:00:00 STATUS DETAIL: Next Step - Open Access REMARKS: Fitria Rahma Nur S fitria.rahma@efishery.com TRUE TRUE None
2 3 5124qwzj2vxv CAHYO SUBEKTI SLEMAN 2021-08-02 00:00:00 Fitria Rahma Nur S fitria.rahma@efishery.com Grade B APPROVED
第二個 dataframe 的切片(實際上只有 header 的列)
No Kode Nominatif Lead ID* Nama Petani Point Tanggal Pengajuan* Nama PIC Utama* Email PIC Utama* Requested Amount Grading Point*
我預期的結果:
No Kode Nominatif Lead ID* Nama Petani Point Tanggal Pengajuan* Nama PIC Utama* Email PIC Utama* Requested Amount Grading Point*
1 nan 5147hvhaau26 AMAN WIJAYA LOMBOK TENGAH 2021-08-01 00:00:00
你能檢查一下這個樣本是否有幫助嗎
df1 = pd.DataFrame({
'col1' : [1,2,3,4,5],
'col2' : [6,7,8,9,10],
'col3': [11,12,13,14,15],
'col4': [16,17,18,19,20]
})
df2 = pd.DataFrame(columns=["col3", "col4", "col5"])
連接使用
pd.concat([df1, df2], axis=0)
結果
col1 col2 col3 col4 col5
0 1.0 6.0 11 16 NaN
1 2.0 7.0 12 17 NaN
2 3.0 8.0 13 18 NaN
3 4.0 9.0 14 19 NaN
4 5.0 10.0 15 20 NaN
IIUC,你的第一個 df 有值,第二個 df 是空的。 第二個 df 在你想要 nan 的地方有額外的列。 讓我知道我的理解是否錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.