Home > Enterprise >  can't access to dataframe values
can't access to dataframe values

Time:02-23

Have a good day everyone..

I have a data frame named Description . enter image description here I showed from rows using :

description.head(5)

When I run this command, my data appears as I created it.

Whereas when I try to extract values for certain rows or columns, I can't do that, so I don't see any values for the entered condition

    age = description.loc[description['subject'] == '50784',['AGE_AT_SCAN']]

    print(age)

Output:

Empty DataFrame

Columns: [AGE_AT_SCAN]

Index: []

Can you help me to solve this problem??

CodePudding user response:

Try this:

age = description.loc[description['subject'] == 50784]['AGE_AT_SCAN']

This will return a series comprised of index and the value at 'AGE_AT_SCAN'. if you're just interested in the value you can add the following:

age = description.loc[description['subject'] == 50784]['AGE_AT_SCAN'].values[0]

This will vectorize the output.

  • Related