简体   繁体   中英

Is there a way to use enumerate starting at a certain column?

So I have a for loop that goes through data frame columns starting at 2:

for col in basis.columns[2:]:

I want to turn it into an enumerate for loop. Kinda like this: for col, x in enumerate(basis):

So that I can access the next values in the loop. (not sure if this is the best way to do it, but that's what I think works lol)

The thing is- I want to start the enumerate at the second column (The 2: part) like in the first example. I'm not really sure how to do that :/ Any help would be really helpful! Thanks

You can do so:

for col, x in enumerate(basis.iloc[:,2:]):

Example:

   a  b  c
0  1  4  7
1  2  5  8
2  3  6  9

for col, x in enumerate(basis.iloc[:,2:]):
    print col, x

Output:

0 c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM