Python中可以使用pandas庫來實現多個表的拼接。具體的方法有以下幾種:
import pandas as pd
# 創建多個表
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df2 = pd.DataFrame({'A': [7, 8, 9], 'B': [10, 11, 12]})
# 按行拼接
result1 = pd.concat([df1, df2], axis=0)
# 按列拼接
result2 = pd.concat([df1, df2], axis=1)
import pandas as pd
# 創建多個表
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'key': ['a', 'b', 'c']})
df2 = pd.DataFrame({'C': [7, 8, 9], 'D': [10, 11, 12], 'key': ['a', 'b', 'c']})
# 根據鍵合并
result = pd.merge(df1, df2, on='key')
import pandas as pd
# 創建多個表
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
df2 = pd.DataFrame({'C': [7, 8, 9], 'D': [10, 11, 12]}, index=['b', 'c', 'd'])
# 根據索引合并
result = df1.join(df2, how='outer')