Skip to content Skip to sidebar Skip to footer

Extracting A Single Data From Pandas Data Frame

How do you extract a value (string) from a given Dataframe, given a certain value from a different column. For example, I would like to get the 'Adrs' where 'Value'=2 import pandas

Solution 1:

>>> df.loc[df['Value'] == 2, 'Adrs'].values[0]
'BBB'>>> df.iat[1, 0]
'BBB'>>> df.at[1, 'Adrs']
'BBB'

Are a few ways. I'm sure there's more.

Solution 2:

df2.Adrs is still a Series, so what you want to do is grab one element from it. df2.Adrs.iloc(0) will get you the first element, regardless of indexing. But what will you do if df2 has multiple rows?

Post a Comment for "Extracting A Single Data From Pandas Data Frame"