简体   繁体   中英

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:

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

You can use the.iloc attribute. Below is an example:

  df.iloc[1,2]

This gets the object at row 1 and column 2.

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.

More information on iloc can be found here:

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

Hope this helps

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