Update app.py
Browse files
app.py
CHANGED
@@ -516,9 +516,19 @@ def server(input, output, session):
|
|
516 |
("rhh_percent", "rhh_percent_old"),
|
517 |
("lhh_percent", "lhh_percent_old"),
|
518 |
]
|
519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
# percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
521 |
-
|
522 |
# Step 2: Format the columns with (value (+diff)) - exclude brackets if diff is 80
|
523 |
df_merge = df_merge.with_columns([
|
524 |
pl.when(pl.col(new + "_diff").eq(10000)) # If diff is 80, no need to include brackets
|
@@ -527,7 +537,7 @@ def server(input, output, session):
|
|
527 |
(pl.col(new)*100).round(1).map_elements(lambda x: f"{x:.1f}%").cast(pl.Utf8) +
|
528 |
"\n(" +
|
529 |
(pl.col(new + "_diff")*100).round(1)
|
530 |
-
.map_elements(lambda x: f"{x:+.1f}") +
|
531 |
")"
|
532 |
).alias(new + "_formatted")
|
533 |
for new, _ in cols_to_subtract_percent
|
@@ -536,7 +546,6 @@ def server(input, output, session):
|
|
536 |
|
537 |
|
538 |
|
539 |
-
|
540 |
# df_merge = df_merge.with_columns([
|
541 |
# (pl.col(col) * 100) # Convert to percentage
|
542 |
# .round(1) # Round to 1 decimal
|
|
|
516 |
("rhh_percent", "rhh_percent_old"),
|
517 |
("lhh_percent", "lhh_percent_old"),
|
518 |
]
|
519 |
+
|
520 |
+
|
521 |
+
df_merge = df_merge.with_columns([
|
522 |
+
# Step 1: Create _diff columns with the default value (e.g., 80) if old is null
|
523 |
+
pl.when(pl.col(old).is_null())
|
524 |
+
.then(pl.lit(10000)) # If old is null, assign 80 as the default
|
525 |
+
.otherwise(pl.col(new) - pl.col(old)) # Otherwise subtract old from new
|
526 |
+
.alias(new + "_diff")
|
527 |
+
for new, old in cols_to_subtract_percent
|
528 |
+
])
|
529 |
+
|
530 |
# percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
531 |
+
|
532 |
# Step 2: Format the columns with (value (+diff)) - exclude brackets if diff is 80
|
533 |
df_merge = df_merge.with_columns([
|
534 |
pl.when(pl.col(new + "_diff").eq(10000)) # If diff is 80, no need to include brackets
|
|
|
537 |
(pl.col(new)*100).round(1).map_elements(lambda x: f"{x:.1f}%").cast(pl.Utf8) +
|
538 |
"\n(" +
|
539 |
(pl.col(new + "_diff")*100).round(1)
|
540 |
+
.map_elements(lambda x: f"{x:+.1f}%") +
|
541 |
")"
|
542 |
).alias(new + "_formatted")
|
543 |
for new, _ in cols_to_subtract_percent
|
|
|
546 |
|
547 |
|
548 |
|
|
|
549 |
# df_merge = df_merge.with_columns([
|
550 |
# (pl.col(col) * 100) # Convert to percentage
|
551 |
# .round(1) # Round to 1 decimal
|