Spaces:
Running
Running
Upload leaderboard_utils.py
Browse files- src/leaderboard_utils.py +15 -2
src/leaderboard_utils.py
CHANGED
@@ -95,9 +95,22 @@ def process_df(df: pd.DataFrame) -> pd.DataFrame:
|
|
95 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
96 |
|
97 |
# Remove repetition in model names
|
98 |
-
df[df.columns[0]] = df[df.columns[0]].str.replace('-
|
99 |
df[df.columns[0]] = df[df.columns[0]].apply(lambda x: '--'.join(set(x.split('--'))))
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
# Update column names
|
102 |
custom_column_names = ['Model', 'Clemscore', '% Played', 'Quality Score']
|
103 |
for i, col in enumerate(df.columns[4:]): # Start Capitalizing from the 5th column
|
@@ -107,7 +120,7 @@ def process_df(df: pd.DataFrame) -> pd.DataFrame:
|
|
107 |
|
108 |
# Rename columns
|
109 |
df.columns = custom_column_names
|
110 |
-
|
111 |
return df
|
112 |
|
113 |
|
|
|
95 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
96 |
|
97 |
# Remove repetition in model names
|
98 |
+
df[df.columns[0]] = df[df.columns[0]].str.replace(r'-t[0-1]\.\d+', '', regex=True)
|
99 |
df[df.columns[0]] = df[df.columns[0]].apply(lambda x: '--'.join(set(x.split('--'))))
|
100 |
|
101 |
+
# Rename the first column to 'Model' if it starts with 'Unnamed'
|
102 |
+
if df.columns[0].startswith('Unnamed'):
|
103 |
+
df.rename(columns={df.columns[0]: 'Model'}, inplace=True)
|
104 |
+
|
105 |
+
# Define the desired column order
|
106 |
+
desired_columns = ['Model', '-, clemscore', 'all, Average % Played', 'all, Average Quality Score']
|
107 |
+
|
108 |
+
# Ensure the DataFrame has all the desired columns
|
109 |
+
existing_columns = [col for col in desired_columns if col in df.columns]
|
110 |
+
|
111 |
+
# Reorder other DataFrame columns
|
112 |
+
df = df[existing_columns + [col for col in df.columns if col not in existing_columns]]
|
113 |
+
|
114 |
# Update column names
|
115 |
custom_column_names = ['Model', 'Clemscore', '% Played', 'Quality Score']
|
116 |
for i, col in enumerate(df.columns[4:]): # Start Capitalizing from the 5th column
|
|
|
120 |
|
121 |
# Rename columns
|
122 |
df.columns = custom_column_names
|
123 |
+
|
124 |
return df
|
125 |
|
126 |
|