How to view dataframe columns based on a condition?

Viewed 111

enter image description here

For the above example, I want to have a look at the value of outlet_size when Outlet_identifier = OUT049 or any value for that instance. I don't want to produce a new dataframe object and then print it, instead I want to know if there is any function or way to directly view it.

2 Answers

For both columns

df.loc[df['Outlet_identifier'].eq('OUT049'), ['Outlet_identifier', 'outlet_size']]

you can do that with pandas like this :

df = pd.DataFrame({'Outlet_identifier': ['OUT049','OUT018','OUT049'], 'outlet_size': 
[2.0, 2.0, 2.0]})
df[df["Outlet_identifier"]=="OUT049"]["outlet_size"]
Related