本文为大家分享了python的concat等多种用法,供大家参考,具体内容如下
1、numpy中的concatenate()函数:
>>> a = np.array([[1, 2], [3, 4]])
>>> b = np.array([[5, 6]])
>>> np.concatenate((a, b), axis=0)
array([[1, 2],
[3, 4],
[5, 6]])
>>> np.concatenate((a, b.T), axis=1)
array([[1, 2, 5],
[3, 4, 6]])
2、pandas中的merge,concat,join
# In[]:数据的合并
# 1 ,merge,类似数据库中的
# (1)内连接,pd.merge(a1, a2, on='key')
# (2)左连接,pd.merge(a1, a2, on='key', how='left')
# (3)右连接,pd.merge(a1, a2, on='key', how='right')
# (4)外连接, pd.merge(a1, a2, on='key', how='outer')
data1 = pd.DataFrame(
np.arange(0,16).reshape(4,4),
columns=