Spaces:
Sleeping
Sleeping
ProtonDataLabs
commited on
Commit
•
2aa750a
1
Parent(s):
a2ed34a
Update app.py
Browse files
app.py
CHANGED
@@ -470,6 +470,42 @@ if st.session_state['active_card'] == 'card3':
|
|
470 |
agg_df_filtered = agg_df_filtered.dropna(subset=['PE_Coeff'])
|
471 |
st.dataframe(agg_df_filtered)
|
472 |
st.write(agg_df_filtered.shape)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
# Plot the PE Coefficient with Plotly
|
474 |
fig = px.line(
|
475 |
agg_df_filtered,
|
|
|
470 |
agg_df_filtered = agg_df_filtered.dropna(subset=['PE_Coeff'])
|
471 |
st.dataframe(agg_df_filtered)
|
472 |
st.write(agg_df_filtered.shape)
|
473 |
+
# Extract values for the current and previous years from row 1 and row 2 of the dataframe
|
474 |
+
current_year_row = agg_df_filtered.iloc[1] # Row 1 - Current Year
|
475 |
+
previous_year_row = agg_df_filtered.iloc[0] # Row 2 - Previous Year
|
476 |
+
|
477 |
+
# Extract values for Unit Price and Sales Volume
|
478 |
+
unit_price_current_year = current_year_row['UnitPrice']
|
479 |
+
unit_price_previous_year = previous_year_row['UnitPrice']
|
480 |
+
sales_volume_current_year = current_year_row['SalesVolume']
|
481 |
+
sales_volume_previous_year = previous_year_row['SalesVolume']
|
482 |
+
|
483 |
+
# Calculate percentage changes for Unit Price and Sales Volume
|
484 |
+
unit_price_pct = ((unit_price_current_year - unit_price_previous_year) / unit_price_previous_year) * 100
|
485 |
+
sales_volume_pct = ((sales_volume_current_year - sales_volume_previous_year) / sales_volume_previous_year) * 100
|
486 |
+
|
487 |
+
# Calculate PE Coefficient
|
488 |
+
pe_coeff = sales_volume_pct / unit_price_pct
|
489 |
+
|
490 |
+
# Render LaTeX formulas with dynamic values using st.latex
|
491 |
+
st.latex(rf"""
|
492 |
+
\text{{Unit Price \% Change}} = \frac{{\text{{Unit Price in Current Year}} - \text{{Unit Price in Previous Year}}}}{{\text{{Unit Price in Previous Year}}}} \times 100 = \frac{{{unit_price_current_year:.2f} - {unit_price_previous_year:.2f}}}{{{unit_price_previous_year:.2f}}} \times 100 = {unit_price_pct:.2f}\%
|
493 |
+
""")
|
494 |
+
|
495 |
+
st.latex(rf"""
|
496 |
+
\text{{Sales Volume \% Change}} = \frac{{\text{{Sales Volume in Current Year}} - \text{{Sales Volume in Previous Year}}}}{{\text{{Sales Volume in Previous Year}}}} \times 100 = \frac{{{sales_volume_current_year:.2f} - {sales_volume_previous_year:.2f}}}{{{sales_volume_previous_year:.2f}}} \times 100 = {sales_volume_pct:.2f}\%
|
497 |
+
""")
|
498 |
+
|
499 |
+
st.latex(rf"""
|
500 |
+
\text{{PE Coefficient}} = \frac{{\text{{Sales Volume \% Change}}}}{{\text{{Unit Price \% Change}}}} = \frac{{{sales_volume_pct:.2f}}}{{{unit_price_pct:.2f}}} = {pe_coeff:.2f}
|
501 |
+
""")
|
502 |
+
# Explanation Text
|
503 |
+
st.markdown(f"""
|
504 |
+
### Explanation of Calculations (for {current_year_row['Region']}, {current_year_row['Itemtype']}, FY {current_year_row['Fy']}):
|
505 |
+
- **Unit Price Percentage Change**: The percentage change in unit price YOY. For FY {current_year_row['Fy']}, the unit price changed by **{unit_price_pct:.2f}%**.
|
506 |
+
- **Sales Volume Percentage Change**: The percentage change in sales volume YOY. For FY {current_year_row['Fy']}, the sales volume changed by **{sales_volume_pct:.2f}%**.
|
507 |
+
- **Price Elasticity (PE) Coefficient**: The PE coefficient for FY {current_year_row['Fy']} is **{pe_coeff:.2f}**.
|
508 |
+
""")
|
509 |
# Plot the PE Coefficient with Plotly
|
510 |
fig = px.line(
|
511 |
agg_df_filtered,
|