I would like to select from a pandas dataframe specific columns using column index.
In particular, I would like to select columns index by the column index generated by c(12:26,69:85,96:99,134:928,933:935,940:967) in R. I wonder how can I do that in Python?
I am thinking something like the following, but of course, python does not have a function called c()...
input2 = input2.iloc[:,c(12:26,69:85,96:99,134:928,933:935,940:967)]
You can pass a list of columns to [] to select columns in that order. If a column is not contained in the DataFrame, an exception will be raised. Multiple columns can also be set in this manner.c(12:26,69:85,96:99,134:928,933:935,940:967), but I do not know how to do that in Python. Thanks!list(range(12, 26) + range(69, 85) + range(96, 99) + range(134, 928) + range(933, 935) + range(940, 967))c()for (numerical) dataframe column indices, or also for concatenating (string) column names ('labels' in Pandas terminology)?pandas.loc[:, ['a','b','c']]can handle both, whereasnumpy.r_only works on numerical indices, not string labels