Pandas 连接数据集 发表于 2018-04-21 | 分类于 编程 | 1. 连接两个dataframe数据集123import numpy as npimport pandas as pdfrom pandas import Series, DataFrame 1234567891011121314151617181920212223df_1 = DataFrame(np.arange(16).reshape(4,4)) 0 1 2 30 0 1 2 31 4 5 6 72 8 9 10 113 12 13 14 15df_2 = DataFrame(np.arange(4).reshape(2,2)) 0 10 0 11 2 3# 将df_1和df_2连接起来pd.concat([df_1,df_2],axis = 1) #在列上进行连接。pd.concat([df_1,df_2])表示在行上进行连接0 1 2 3 0 10 0 1 2 3 0.0 1.01 4 5 6 7 2.0 3.02 8 9 10 11 NaN NaN3 12 13 14 15 NaN NaN # 另外一种连接方法df_1.append(df_2,ignore_index = True) 2.将dataframe 和series连接起来123456789series = Series([3,4,5,6])series.name = 'added_series'pd.concat([df_1,series],axis = 1)0 1 2 3 added_series0 0 1 2 3 31 4 5 6 7 42 8 9 10 11 53 12 13 14 15 6 3.去掉指定行或者列1234567891011df_1.drop([0,1])0 1 2 32 8 9 10 113 12 13 14 15df_1.drop([0,1],axis = 1)2 30 2 31 6 72 10 113 14 15