how to make a new dataframe from an existig dataframe by averaging out some of the columns?

I would first create a dictionary with the averages and then convert it into a DataFrame

res = {}
for col in cols:
    if col == "TEST_TXT":
        pass
    elif col in ["min","max"]:
        res[col] = np.min(group_dataframe[col].astype(float))
    else:
        res[col] = np.mean(group_dataframe[col].astype(float))

new_df = pd.DataFrame(res)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top