Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: Iterate through columns and starting at one column

Does anyone know how to incorporate a forloop for columns but start at any column? (The third one for this scenario)

Lets say this is the dataframe:

spice smice skice bike dike mike 
1     23     35    34   34   56 
135   34     23    21   56   34
231   12     67    21   62   75

I want to iterate through skice, bike, dike, and mike only

like image 992
bobo T Avatar asked Dec 10 '22 06:12

bobo T


1 Answers

Since df.columns provides you the list of columns, you can do below and iterate from 3rd column name.

for col in df.columns[2:]:
    #print(df[col].unique())
like image 53
harvpan Avatar answered Mar 15 '23 19:03

harvpan