James McCool
commited on
Commit
·
40fb788
1
Parent(s):
3c99d96
Add team stacking logic in app.py: implement a new feature to determine the most common team for players in the portfolio, enhancing team analysis capabilities and improving user insights into player distributions.
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import time
|
|
| 6 |
from rapidfuzz import process, fuzz
|
| 7 |
import random
|
| 8 |
import re
|
|
|
|
| 9 |
|
| 10 |
## import global functions
|
| 11 |
from global_func.clean_player_name import clean_player_name
|
|
@@ -230,6 +231,15 @@ with tab1:
|
|
| 230 |
projections['player_names'] = projections['player_names'].map(lambda x: projections_match_dict.get(x, x))
|
| 231 |
st.session_state['projections_df'] = projections
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
working_frame = st.session_state['portfolio'].copy()
|
| 234 |
try:
|
| 235 |
st.session_state['export_dict'] = dict(zip(st.session_state['csv_file']['Name'], st.session_state['csv_file']['Name + ID']))
|
|
|
|
| 6 |
from rapidfuzz import process, fuzz
|
| 7 |
import random
|
| 8 |
import re
|
| 9 |
+
from collections import Counter
|
| 10 |
|
| 11 |
## import global functions
|
| 12 |
from global_func.clean_player_name import clean_player_name
|
|
|
|
| 231 |
projections['player_names'] = projections['player_names'].map(lambda x: projections_match_dict.get(x, x))
|
| 232 |
st.session_state['projections_df'] = projections
|
| 233 |
|
| 234 |
+
team_dict = dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team']))
|
| 235 |
+
st.session_state['portfolio']['stack'] = st.session_state['portfolio'].apply(
|
| 236 |
+
lambda row: Counter(
|
| 237 |
+
team_dict.get(player, '') for player in row[2:]
|
| 238 |
+
if team_dict.get(player, '') != ''
|
| 239 |
+
).most_common(1)[0][0] if any(team_dict.get(player, '') for player in row[2:]) else '',
|
| 240 |
+
axis=1
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
working_frame = st.session_state['portfolio'].copy()
|
| 244 |
try:
|
| 245 |
st.session_state['export_dict'] = dict(zip(st.session_state['csv_file']['Name'], st.session_state['csv_file']['Name + ID']))
|