Assuming you have two tables "a" and "b" with a common column "id", you can use the following script to perform an inner join in Python using pandas library:

import pandas as pd

# create table a
a = pd.DataFrame({'id': [1, 2, 3, 4], 'name': ['John', 'Alice', 'Bob', 'Sarah']})

# create table b
b = pd.DataFrame({'id': [2, 4, 5], 'age': [25, 30, 35]})

# perform inner join on column 'id'
result = pd.merge(a, b, on='id', how='inner')

print(result)

Output:

   id   name  age
0   2  Alice   25
1   4  Sarah   30

The script uses the pd.merge() function to merge the two tables on the common column "id" using an inner join. The resulting table only includes rows where the "id" column exists in both tables "a" and "b"

how to inner join table a and b in python show me script

原文地址: https://www.cveoy.top/t/topic/eCjz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录