<jupyter_start><jupyter_text>Defining your own index, rather than the default index of 0...N may be useful when you need to organize data logically, for example time series data can use the time as indexBut luckily, you also have access to the 0...N index by using the "iloc" selector<jupyter_code>df["age"]
df["weight"].values # .values returns the column as an array
df.describe()
df
sel_UU = (df["university"] == "Unseen")
sel_UU
sel_UU = (df["university"] == "Unseen")
df.loc[sel_UU] # You can use boolean selectors to select slices of the dataframe
df_UU = df.loc[sel_UU]
df_UU.loc["A", "age"] = 21
df
df
df.groupby("university").count()
df.groupby("university").mean()
df.groupby("university").std()
df.loc[df["age"] > 25]
df.loc[df["age"] > 25, "names"]
df.loc[df["age"] > 25, "weight"] * 1.25
df.loc[df["age"] > 25, "weight"] = df.loc[df["age"] > 25, "weight"] * 1.25<jupyter_output><empty_output><jupyter_text>You can define your own functions and perform operations on grouped dataframes using "apply"Let's say that a magical accident ages everyone at Unseen University by 25 years, we can update our dataframe by grouping it by "university" and then adding 25 years to the ages of those in UU.<jupyter_code>def increase_age(gdf, addYears=25):
    print(gdf)
    if gdf.loc[:, "university"][0] == "Unseen": # conditional statement to perform the operation only on Unseen University members
        gdf.loc[:, "age"] = gdf["age"] + addYears
    return gdf
df.groupby("university").count()
df = df.groupby("university").apply(increase_age)
df
pd.cut?
df.groupby(pd.cut(df["age"], [20,30,40,100])).count()<jupyter_output><empty_output><jupyter_text>pd.cut() function allows us to bin the data. You pass the column followed by the bins and then call a function that operates on the grouped dataframe.  Exercise 08: Practise groupby operations1. Groupby university name and use the following functions: count, mean, std, describe1. Groupby weight, binned in (0,50], (50, 100], (100,150], (150, 200] bins and call the count and mean functions.1. Can you draw a flowchart describing the groupby() and apply() operation? Discuss this with your group members!<jupyter_code>df.groupby( pd.cut(df["weight"], [0, 50, 100, 150, 200])).describe()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup