Update app.py
Browse files
app.py
CHANGED
|
@@ -514,18 +514,33 @@ def server(input, output, session):
|
|
| 514 |
|
| 515 |
|
| 516 |
|
|
|
|
| 517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
|
| 519 |
|
| 520 |
-
percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
| 521 |
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
|
|
|
|
|
|
| 529 |
|
| 530 |
|
| 531 |
columns = [
|
|
|
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
+
percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
| 518 |
|
| 519 |
+
# Step 2: Format the columns with (value (+diff)) - exclude brackets if diff is 80
|
| 520 |
+
df_merge = df_merge.with_columns([
|
| 521 |
+
pl.when(pl.col(new + "_diff").eq(10000)) # If diff is 80, no need to include brackets
|
| 522 |
+
.then(pl.col(new).round(1).cast(pl.Utf8)+'\n\t') # Just return the new value as string
|
| 523 |
+
.otherwise(
|
| 524 |
+
pl.col(new).round(1).cast(pl.Utf8) +
|
| 525 |
+
"\n(" +
|
| 526 |
+
pl.col(new + "_diff").round(1)
|
| 527 |
+
.map_elements(lambda x: f"{x:+.1f}%") +
|
| 528 |
+
")"
|
| 529 |
+
).alias(new + "_formatted")
|
| 530 |
+
for new, _ in cols_to_subtract
|
| 531 |
+
])
|
| 532 |
|
| 533 |
|
|
|
|
| 534 |
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
# df_merge = df_merge.with_columns([
|
| 538 |
+
# (pl.col(col) * 100) # Convert to percentage
|
| 539 |
+
# .round(1) # Round to 1 decimal
|
| 540 |
+
# .map_elements(lambda x: f"{x:.1f}%") # Format as string with '%'
|
| 541 |
+
# .alias(col + "_formatted")
|
| 542 |
+
# for col in percent_cols
|
| 543 |
+
# ]).sort(['pitcher_id','count'],descending=True)
|
| 544 |
|
| 545 |
|
| 546 |
columns = [
|