문제

I have data in the form of a list of lists. I wanted to do something like (data[1::100])[3], where I access the first 100 elements, and then just the third column of all those elements. In tutorials on Kaggle, I had seen things like data[1::100,3], but Python says:

TypeError: list indices must be integers, not tuple.

Is there an easy way to do this? I could just use a loop or something, but this will come up a lot so it would be nice to have some shorthand.

도움이 되었습니까?

해결책

In a list of lists, you can do:

values = [l[3] for l in data[:100]]

to achieve the same thing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top