使用
numpy.intersect1d或
intersection:
a = np.intersect1d(df2.columns, df1.columns)print (a)['B' 'C']a = df2.columns.intersection(df1.columns)print (a)Index(['B', 'C'], dtype='object')
后一种选择的替代语法:
df1.columns & df2.columns

使用
numpy.intersect1d或
intersection:
a = np.intersect1d(df2.columns, df1.columns)print (a)['B' 'C']a = df2.columns.intersection(df1.columns)print (a)Index(['B', 'C'], dtype='object')
后一种选择的替代语法:
df1.columns & df2.columns