google-research/rliable
View on GitHubAdd support for loading data from pandas dataframe
Open
#18 opened on Jan 18, 2023
enhancementgood first issuehelp wanted
Repository metrics
- Stars
- (875 stars)
- PR merge metrics
- (PR metrics pending)
Description
Right now, we only support loading data from numpy arrays. It would be nice if there was a helper function to convert a dataframe of scores to numpy arrays. Some initial code to help what this might look like:
def get_all_return_values(df):
games = list(df['game'].unique())
return_vals = {}
for game in games:
game_df = df[df['game'] == game]
arr = game_df.groupby('wid')['normalized_score'].apply(list).values
return_vals[game] = np.stack(arr, axis=0)
return return_vals
def convert_to_matrix(x):
return np.stack([x[k] for k in sorted(x.keys())], axis=1)
## Usage
# Array of shape (num_runs, num_games, num_steps)`
all_normalized_scores = convert_to_matrix(get_all_return_values(score_df))
The above code assumes we have a pandas Dataframe with keys run_number, 'gameandnormalized_score` containing scores for all steps (in a ordered manner).