简体   繁体   English

在 Pandas 中查找行索引和列索引值

[英]finding a row index and column index value in Pandas

I want to find a index of row, by giving definite column number.我想通过给出明确的列号来找到行的索引。

import pandas as pd
list1=[['a1','a2','a3'],['b1','b2','b3'],['c1','c2','c3']]
df = pd.DataFrame(list1)

在此处输入图像描述

how can I find it?我怎样才能找到它?

To get it, you have to use iloc in the following way:要获得它,您必须按以下方式使用 iloc:

print(df.iloc[1][1])

You can use the.iloc attribute.您可以使用 .iloc 属性。 Below is an example:下面是一个例子:

  df.iloc[1,2]

This gets the object at row 1 and column 2.这将在第 1 行和第 2 列获得 object。

You can even splice using a colon.您甚至可以使用冒号进行拼接。 Example:例子:

  df.iloc[2:5 , 3:8]

This gets all the elements from rows 2 to 5 and 3 to 8.这将获取第 2 行到第 5 行和第 3 行到第 8 行的所有元素。

More information on iloc can be found here:关于 iloc 的更多信息可以在这里找到:

https://thispointer.com/select-rows-columns-by-name-or-index-in-dataframe-using-loc-iloc-python-pandas/ https://thispointer.com/select-rows-columns-by-name-or-index-in-dataframe-using-loc-iloc-python-pandas/

Hope this helps希望这可以帮助

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

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