拼接
拼接
# 连接:concat s1 = pd.Series([1,2,3]) s2 = pd.Series([2,3,4]) print(pd.concat([s1,s2])) print('-----') # 默认axis=0,行+行 s3 = pd.Series([1,2,3],index = ['a','c','h']) s4 = pd.Series([2,3,4],index = ['b','e','d']) print(pd.concat([s3,s4]).sort_index()) print(pd.concat([s3,s4], axis=1)) print('-----') # axis=1,列+列,成为一个Dataframe
|
|
import numpy as np import pandas as pd df1 = pd.DataFrame([[1,2,3],[1,2,3],[1,2,3]],index=list('abc'),columns=list('ABC')) df2 = pd.DataFrame([[1,2,3],[1,2,3],[1,2,3]],index=list('abd'),columns=list('ABD')) print('-----行方向完全相同的进行合并------') dd = pd.concat([df1,df2]) print(dd) print('-----列方向完全相同的进行合并------') dd = pd.concat([df1,df2],axis=1) print(dd) |