Pandas Dataframe select multiple discontinuous columns/slices
问题 I have dataframe with >100 columns. I am trying to select the columns 0~32 and #83. It seems that 1 slice works fine with the code below. df_new = df[df.columns[0:32]] It does not work with 2 slices code below though. How do I fix the problem? df_new = df[df.columns[0:32, 83]] 回答1: Use the np.r_ indexer in conjunction with iloc , like this: df.iloc[:, np.r_[0:32, 83]] np.r_[0:32, 83] array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,