Reduce repetition in Pandas DataFrame column assignments Could the aggregate functions after using grouping functions like groupby() and resample() be looped for cleaner code

____DateTime.____    |  Steps  | day_segment
2017-10-25 00:00:00| 4  | night
2017-10-25 00:01:00| 7  | night
2017-10-25 00:02:00| 10 | night
2017-10-25 00:03:00| 26 | night
.
.
.
2017-10-25 10:04:00| 80 | morning
2017-10-25 10:05:00| 45 | morning
2017-10-25 10:06:00| 53 | morning  

DataFrame: data

day_segments = ['morning','afternoon','evening','night']
#all_steps is a list input from the user
all_steps = ['sumallsteps','maxallsteps','minallsteps','avgallsteps','stdallsteps']
finalDataset = pd.DataFrame()

#Descriptive Statistics Features:
for day_segment in day_segments:
    resampledData = pd.DataFrame()
    resampledData = data.loc[data['day_segment'] == str(day_segment)]
    if("sumallsteps" in all_steps):
        finalDataset["step_" + str(day_segment) + "_sumallsteps"] = resampledData['steps'].resample('D').sum()

    if("maxallsteps" in all_steps):
        finalDataset["step_" + str(day_segment) + "_maxallsteps"] = resampledData['steps'].resample('D').max()

    if("minallsteps" in all_steps):
        finalDataset["step_" + str(day_segment) + "_minallsteps"] = resampledData['steps'].resample('D').min()

    if("avgallsteps" in all_steps):
        finalDataset["step_" + str(day_segment) + "_avgallsteps"] = resampledData['steps'].resample('D').mean()

    if("stdallsteps" in all_steps):
        finalDataset["step_" + str(day_segment) + "_stdallsteps"] = resampledData['steps'].resample('D').std()
    finaDataset.to_csv('data'+str(day_segment)+'.csv',index=True)


IS THERE A WAY TO MAKE THE 'IF' STATEMENTS AND ITS FUNCTIONS SHORTER? LOOP IT IN A DICTIONARY SOMEHOW?

There are more assignments like this in my code so I would want to know if there is a way I could just loop the aggregate functions
Try to get a good book or tutorial about pandas. The things you want to do is relatively easy with groupby.agg

for segment, segment_data in df.groupby("day_segment"):
    aggregated_data = segment_data.resample("D").agg(
        ["sum", "mean", "std", "min", "max"]
    )
    aggregated_data_renamed = aggregated_data.copy()
    aggregated_data_renamed.columns = aggregated_data.columns.droplevel(0).map(
        lambda x: f"step_{segment}_{x}allsteps"
    )

    filename = f"data{segment}.csv"
    aggregated_data_renamed.to_csv(filename, index=True)


This uses mean instead of avg. If this is a problem, you can add another rename function call somewhere