Pandas如何串联数据()

NumPy的连接数据用于按行或列连接两个数组。它可以采用两个或更多个相同形状的数组, 并且按行串联作为默认类型, 即axis = 0。
范例1:

# import numpyimport numpy as nparr1 = np.arange(9)arr1arr2d_1 = array.reshape((3, 3))arr2d_1 arr2d_1 = np.arange(10, 19).reshape(3, 3)arr2d_1# concatenate 2 numpy arrays: row-wisenp.concatenate((arr2d_1, arr2d_2))

输出
array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [10, 11, 12], [13, 14, 15], [16, 17, 18]])

范例2:
import pandas as pdone = pd.DataFrame({'Name': ['Parker', 'Phill', 'Smith'], 'id':[108, 119, 127]}, index=['A', 'B', 'C'])two = pd.DataFrame({'Name': ['Terry', 'Jones', 'John'], 'id':[102, 125, 112]}, index=['A', 'B', 'C'])print(pd.concat([one, two]))

输出
NameidAParker108BPhill119CSmith127ATerry102BJones125CJohn112

范例3:
import pandas as pdone = pd.DataFrame({'Name': ['Parker', 'Phill', 'Smith'], 'id':[108, 119, 127]}, index=['A', 'B', 'C'])two = pd.DataFrame({'Name': ['Terry', 'Jones', 'John'], 'id':[102, 125, 112]}, index=['A', 'B', 'C'])print(pd.concat([one, two], keys=['x', 'y']))

【Pandas如何串联数据()】输出
Nameidx AParker108BPhill119 CSmith127y ATerry102 BJones125CJohn112

    推荐阅读