If I have R data.frame dfand
colnames(df)
[1] "a" "b" "c" "d" "e",
I can select the columns "a", "c", "d" and "e" as follows:
df[ , c(1, 3:5)]
Is there a simple equivalent in pandas? I know I can use
df.loc[:, ['a', 'c', 'd', 'e']]
and this is normal for multiple columns.
For many column sequences, the R code is still simple.
df2[ , c(1:10, 25:30, 40, 50:100)]
source
share