how do i find the min and max values of a table based on a condition in another table?

next time please add sample df.

# import pandas
import pandas as pd

# sample df
d = {'Infection': ['Y', 'N', 'Y', 'Y', 'N', 'Y','N'],'Age': [11, 22, 33, 44, 55, 66, 77]}
df = pd.DataFrame(data=d)

# min max age if Infection == Y
print(df[df['Infection']=='Y']['Age'].min())
print(df[df['Infection']=='Y']['Age'].max())

If I missed the point of your question or you need me to clarify anything let me know. Good luck!

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top