Skip to main content
added 158 characters in body
Source Link

I am posting the answer that I came up with. A better and efficient answers are always welcomed.

def avg_dataframe(list_of_dataframes:list, common_index_column:str = 'Model') -> pd.DataFrame :
    scoresheet = None
    for num,i in enumerate(list_of_dataframes):
        i = i.reset_index()
        i = i.sort_values(common_index_column)
        
        if num == 0:
            scoresheet = i
        else:
            scoresheet = pd.concat([scoresheet, i], ignore_index=True)
    return scoresheet
```

and then use groupby method as;

new_scoresheet = avg_dataframe(data_list)

new_scoresheet.groupby('Model').mean()

this worked for me.

I am posting the answer that I came up with. A better and efficient answers are always welcomed.

def avg_dataframe(list_of_dataframes:list, common_index_column:str = 'Model') -> pd.DataFrame :
    scoresheet = None
    for num,i in enumerate(list_of_dataframes):
        i = i.reset_index()
        i = i.sort_values(common_index_column)
        
        if num == 0:
            scoresheet = i
        else:
            scoresheet = pd.concat([scoresheet, i], ignore_index=True)
    return scoresheet
```

I am posting the answer that I came up with. A better and efficient answers are always welcomed.

def avg_dataframe(list_of_dataframes:list, common_index_column:str = 'Model') -> pd.DataFrame :
    scoresheet = None
    for num,i in enumerate(list_of_dataframes):
        i = i.reset_index()
        i = i.sort_values(common_index_column)
        
        if num == 0:
            scoresheet = i
        else:
            scoresheet = pd.concat([scoresheet, i], ignore_index=True)
    return scoresheet

and then use groupby method as;

new_scoresheet = avg_dataframe(data_list)

new_scoresheet.groupby('Model').mean()

this worked for me.

Source Link

I am posting the answer that I came up with. A better and efficient answers are always welcomed.

def avg_dataframe(list_of_dataframes:list, common_index_column:str = 'Model') -> pd.DataFrame :
    scoresheet = None
    for num,i in enumerate(list_of_dataframes):
        i = i.reset_index()
        i = i.sort_values(common_index_column)
        
        if num == 0:
            scoresheet = i
        else:
            scoresheet = pd.concat([scoresheet, i], ignore_index=True)
    return scoresheet
```