Python ProgrammingPython Programming

Get cell value from a Pandas DataFrame row

Get list of cell value conditionally:

import pandas as pd

df = pd.DataFrame({'Age': [30, 40, 30, 40, 30, 30, 20, 25],
                   'Height': [120, 162, 120, 120, 120, 72, 120, 81]},
                  index=['Jane', 'Jane', 'Aaron', 'Penelope', 'Jaane', 'Nicky',
                         'Armour', 'Ponting'])


print(df.loc[df.Age == 30,'Height'].tolist())



C:\python\examples>python example58.py
[120, 120, 120, 72]
 
C:\python\examples>