I have been mainly an R user up until now, and I am now trying to get better with Python, so please keep that in mind as I may not be thinking in a pythonic way...
In any case, here it goes, I want to subset a pandas dataframe by column position, where I would select for instance, the first 2 columns, the the 4th column, and then the last two columns.
The code I used for that is as follows:
df01 = pd.DataFrame(np.random.randint(low=0, high=10, size=(10, 10)),
columns=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i','j'])
df01.iloc[:,list(range(0,2)) + list([3]) + list(range(-3,-1))]
I am doing the subsetting by essentially creating 3 lists with the columns I want, but I am thinking there must be a better way to do this as this appears to me as too cumbersome. In R I could just do a simple:
df01[c(1:2,4,9:10)]
Again, this may be just the way it is, but given my status as a python "newbie', Im interested to know if there is a better more concise way.
Thanks,
df.iloc[:,np.r_[1:2,4,9:10]]
. where np isimport numpy as np
np.r_
did the trick and is what I was looking for... Thanks @SandeepKadapa