---
# System prepended metadata

title: Python Pandas DataFrame を`INNER JOIN`する 2021-07-26
tags: [INNER JOIN, Python, DataFrame, Pandas]

---

---
lang: ja-jp
breaks: true
---
# Python Pandas DataFrame を`INNER JOIN`する 2021-07-26

共通の項目 `AdapterPhysicalAddress` で `INNER JOIN` 結合を行う。

```python=
import pandas as pd
from IPython.core.display import display

# 結合先
df = df = pd.read_csv("aaaa.csv")

# 結合元
adapter_number = {
    "00:0F:00:70:CC:47": 1,  # デスク右側
    "00:0F:00:73:A2:9D": 2,  # PC裏側
}
df_adapter = pd.DataFrame(adapter_number.items()).rename(columns={0:"AdapterPhysicalAddress", 1:"adapter_id"})

df = pd.merge(df, df_adapter, on='AdapterPhysicalAddress', how='inner')
display(df)
```

:::warning
`結合先:結合元=N:1`となるようなデータが前提となります。
:::

###### tags: `Pandas` `Python` `DataFrame` `INNER JOIN`
