简体   繁体   English

有没有办法从某一列开始使用枚举?

[英]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循环遍历从2开始的数据帧列:

for col in basis.columns[2:]:

I want to turn it into an enumerate for loop. 我想把它变成枚举for循环。 Kinda like this: for col, x in enumerate(basis): 有点像这样: 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) (不确定这是否是最好的方法,但这就是我认为的工作lol)

The thing is- I want to start the enumerate at the second column (The 2: part) like in the first example. 问题是 - 我想在第二列(第2:部分)开始枚举,就像在第一个例子中一样。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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