Home > other >  pandas python using head
pandas python using head

Time:05-19

in python script, after importing pandas and using print(Properties.head()) I am able to get the properties in table form.

 label  area  equivalent_diameter  centroid-0  centroid-1  centroid-2
0      1  6901            23.621337   10.023185    9.577597    9.209535
1      2   254             7.857391   22.000000    9.062992    5.889764
2      3  1251            13.368609   25.381295    7.811351    8.749001
3      4     1             1.240701   30.000000    0.000000    0.000000
4      5  4573            20.593691   37.957577    9.056855    8.852176

My question, is how I can extract one value from the table, let's say, the centroid-0 column and zero line corresponds to 10.023185. How I can print only this value ?

CodePudding user response:

you can go in two ways using names - .loc():

df.loc[0, 'centroid-0']

or using indexes - .iloc():

df.iloc[0, 4]

CodePudding user response:

TL;DR

    df.loc[0, 'centroid-0'] # extract the 1st value of the column
    df.loc[:, 'centroid-0'] # extract the whole column

Long answer You can use either df.loc or df.iloc. if you wanted to use df.iloc :

    df.iloc[0, 3] # extract the 1st value of the column
    df.iloc[:, 3] # extract the whole column

The main difference is that df.iloc works only with ids.

  • Related