pasztora
2/6/2019 - 11:58 AM

Selecting rows from dataframes

# A new dataframe is created based on the rows of df where Age [h] is the maximum for each Batch ID group
# The new dataframe contains only the rows of the original dataframe, where Age [h] is the maximum
maxAge = df[df.groupby(['Batch ID'])["Age [h]"].transform(max) == df["Age [h]"]]


# Many row selection conditions can be applied together on a dataframe
# Here a new, filtered dataframe is created which satisfies 3 different conditions from 3 columns
df2 = df[(df['Product'] == "Met1") & (df['Max titer [g/L]'] > 50) & (df["Success label"] != "Failed")]