I have a simple pandas dataframe:
import pandas as pd
data = [['tom', 10], ['nick', 15], ['juli', 14]]
df = pd.DataFrame(data, columns = ['Name', 'Age'])
If I select the Name from row index 1, I get a simple string object:
df.loc[1].Name
Out[9]: 'nick'
But if I select the row containing Age == 15, I get an object I can't seem to coerce into a string object
df.loc[df.Age==15].Name
Out[11]:1 nick
Name: Name, dtype: object
type(df.loc[df.Age==15].Name)
Out[38]: pandas.core.series.Series
Ok, its a series, that's cool, get the first element:
df.loc[df.Age==15].Name[0]
KeyError: 0
Well, that didn't work, lets ask for the actual key:
df.loc[df.Age==15].Name[1]
Out[40]: 'nick'
Yeah! That works! ... but if I knew the actual key I wouldn't have done the query in the first place!
How do I get the string value from this Name field if I know the Age? In my real use-case I know Age is unique.