简体   繁体   English

如何使用特定的最后第 n 列获取熊猫中的每第 n 列?

[英]How to get every nth column in pandas with an specific last nth column?

Using the function row[3::2] will return the row from every 2nd column starting from the 3rd column.使用函数row[3::2]将返回从第三列开始的每第二列的行。

But how can you adjust it so it returns up to a certain column?但是如何调整它使其返回到某个列? That is, how can you adjust it so it only gets every 2nd column up to the nth column.也就是说,你如何调整它,使它只得到每 2 列直到第 n 列。

Slicing syntax is start: stop: step , so to return only up to a certain column you can use:切片语法是start: stop: step ,因此要仅返回特定列,您可以使用:

row[3:10:2]

It's also possible to chain indexers like this:也可以像这样链接索引器:

row[3:10][::2]

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

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