我有兩個表:
df1:
index Address type amount Epoch ln of amount
0 0x88aDa02f6fCE2F1A833ad9B4999D62a7e3b70367 outflow 250000.0 1 12.429216
1 0x88aDa02f6fCE2F1A833ad9B4999D62a7e3b70367 outflow 250000.0 2 12.429216
2 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 250000.0 1 12.429216
3 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 33333.0 2 10.414303
4 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 33333.0 3 10.414303
和 df2:
Index Other Addresses
0 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389
我想創建一個只包含來自 df2 的地址(和所有其他相應列)的新表,但行數需要是左側的行數。
基本上,我正在確定 df2 中的哪些地址存在于 df1 中,并且只保留那些地址以及來自其他列的所有資訊。
在我的示例中,結果表如下所示:
index Address type amount Epoch ln of amount
0 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 250000.0 1 12.429216
1 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 33333.0 2 10.414303
2 0xhj2gf34jhl23h23ljhn45b1836hf?lsxsdkjv389 outflow 33333.0 3 10.414303
uj5u.com熱心網友回復:
您可以pandas.Series.isin按照評論中的建議使用:
df1[df1['Address'].isin(df2['Other Addresses])
例子:
df1=pd.DataFrame.from_dict({'col1':[1,2,3],'col2':['x','y','z']})
即df1:
col1 col2
0 1 x
1 2 y
2 3 z
也創建df2:
df2=pd.DataFrame.from_dict({'col1_other':[1,7]})
IE:
col1
0 1
1 7
df1[df1['col1'].isin(df2['col1_other'])] 然后變成:
col1 col2
0 1 x
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315242.html
上一篇:從連接的mysql5.X表中的每一行中獲取至少最后2行
下一篇:通過匹配特定列來連接兩個檔案
