os1187 commited on
Commit
81c96a6
·
1 Parent(s): 1a75c79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -1,26 +1,43 @@
1
  import streamlit as st
 
 
2
 
3
  def load_data():
4
- # Load data into a pandas DataFrame
5
- df = pd.read_csv("tax_data.csv")
6
-
7
- # Perform any necessary data processing and cleaning
8
- df = df.dropna()
9
- df["compliance"] = df["compliance"].astype(int)
10
-
11
  return df
12
 
13
 
14
- def main():
15
  df = load_data()
16
 
17
- st.header("Tax Compliance Analysis")
18
- st.subheader("Data Overview")
 
 
 
19
 
20
- st.write("Number of records: ", df.shape[0])
21
- st.write("Number of compliant records: ", df[df["compliance"] == 1].shape[0])
22
- st.write("Number of non-compliant records: ", df[df["compliance"] == 0].shape[0])
23
 
24
- st.subheader("Compliance by Tax Type")
25
- st.bar_chart(df.groupby("tax_type")["compliance"].mean())
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
 
5
  def load_data():
6
+ df = pd.DataFrame({
7
+ "tax_type": ["Income Tax", "Sales Tax", "Property Tax", "Corporate Tax", "Value Added Tax (VAT)",
8
+ "Income Tax", "Sales Tax", "Property Tax", "Corporate Tax", "Value Added Tax (VAT)"],
9
+ "compliance": [0.75, 0.82, 0.60, 0.70, 0.65,
10
+ 0.79, 0.75, 0.66, 0.72, 0.68]
11
+ })
 
12
  return df
13
 
14
 
15
+ def compliance_analysis(tax_type):
16
  df = load_data()
17
 
18
+ compliance_rate = df[df["tax_type"] == tax_type]["compliance"].mean()
19
+ compliance_rate = round(compliance_rate * 100, 2)
20
+
21
+ df = df.groupby("tax_type").mean().reset_index()
22
+ df = df.sort_values("compliance", ascending=False)
23
 
24
+ fig = px.bar(df, x="compliance", y="tax_type", color="tax_type", orientation="h",
25
+ title="Average Compliance Rate for Tax Types",
26
+ labels={"compliance": "Compliance Rate (%)", "tax_type": "Tax Type"})
27
 
28
+ fig.update_xaxes(ticktext=[str(round(v * 100, 2)) + "%" for v in df["compliance"]],
29
+ tickvals=df["compliance"] * 100)
30
+ fig.update_layout(shapes=[
31
+ dict(type='line', x0=compliance_rate, x1=compliance_rate, y0=0, y1=1, yref='paper',
32
+ line=dict(color='red', dash='dash')),
33
+ dict(type='text', x=compliance_rate, y=1.1, yref='paper',
34
+ text=f"{tax_type} ({compliance_rate}%)", textangle=0, font=dict(color='red', size=12))
35
+ ])
36
+
37
+ return fig
38
+
39
+ tax_types = ["Income Tax", "Sales Tax", "Property Tax", "Corporate Tax", "Value Added Tax (VAT)"]
40
+ selected_tax_type = st.selectbox("Select a tax type:", tax_types, index=0)
41
+
42
+ st.plotly_chart(compliance_analysis(selected_tax_type))
43