[英]Join two Data Frames in Pandas based on third data frame
我有 3 個不同尺寸的熊貓 df 。 第一幀如下——
df1.head(4)
col1 col2 col3
a b c
d e f
g h i
j k l
第二幀如下——
df2.head(4)
col4 col5 col6
m n o
p q r
s t u
v w x
第三個數據幀具有df1
的col3
和df2
col6
的組合。 看起來像
df3.head(3)
col3 col6
c r
i u
f x
現在我想根據df3
列col3
和col6
的組合組合所有三個數據框。 結果 df 應該看起來像-
final_df.head(3)
col1 col2 col4 col5 col2 col6
a b p q c r
g h s t i u
d e v w f x
我試過下面的代碼
df4 = pd.merge(df1, df3, on='col3')
final_df = pd.merge(df4, df2, on='col6')
但得到了內存錯誤
MemoryError: Unable to allocate 1.79 GiB for an array with shape (2, 120193432) and data type int64
有沒有其他有效的方法來做到這一點?
以上工作正常,我這邊沒有內存錯誤。 我正在運行帶有 32 位 python 的 8Gig Ram 計算機。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.