soroushsrd commited on
Commit
5bdd16f
·
verified ·
1 Parent(s): bd95fdc

Upload 2 files

Browse files
Files changed (2) hide show
  1. main (1).py +99 -0
  2. requirements.txt +3 -0
main (1).py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Load data
6
+ data = pd.read_csv('customers.csv')
7
+
8
+
9
+ # Function to display basic data information
10
+ def display_data_info(data):
11
+ st.write("### Data Information")
12
+ st.write(data.info())
13
+ st.write("### Data Description")
14
+ st.write(data.describe())
15
+
16
+
17
+ # Function to plot data
18
+ def plot_data(data, column, chart_type):
19
+ if column == 'Net Sale':
20
+ data[column] = data[column].replace('[\$,]', '', regex=True).str.strip()
21
+ data[column] = pd.to_numeric(data[column], errors='coerce')
22
+ elif column == 'Cost':
23
+ data[column] = data[column].replace('[\$,]', '', regex=True).str.strip()
24
+ data[column] = pd.to_numeric(data[column], errors='coerce')
25
+ elif column == 'Gross Profit':
26
+ data[column] = data[column].replace('[\$,]', '', regex=True).str.strip()
27
+ data[column] = pd.to_numeric(data[column], errors='coerce')
28
+ elif column == ' AVG Inv. ':
29
+ data[column] = data[column].replace('[\$,]', '', regex=True).str.strip()
30
+ data[column] = pd.to_numeric(data[column], errors='coerce')
31
+
32
+ grouped_data = data.groupby('Mail ZIP')[column].sum()
33
+
34
+ plt.figure(figsize=(10, 6))
35
+ if chart_type == 'Bar Chart':
36
+ grouped_data.plot(kind='bar', color='skyblue')
37
+ elif chart_type == 'Scatter Plot':
38
+ plt.scatter(grouped_data.index, grouped_data.values, color='skyblue')
39
+ elif chart_type == 'Line Chart':
40
+ grouped_data.plot(kind='line', color='skyblue')
41
+ plt.title(f'{column} by ZIP Code')
42
+ plt.xlabel('ZIP Code')
43
+ plt.ylabel(column)
44
+ plt.xticks(rotation=45)
45
+ st.pyplot(plt)
46
+
47
+
48
+ # Function to plot gross margin by ZIP Code
49
+ def gross_margin_by_zip_code(data, chart_type):
50
+ margin_by_zip = data.groupby('Mail ZIP')['Gross Margin'].mean()
51
+ plt.figure(figsize=(10, 6))
52
+ if chart_type == 'Bar Chart':
53
+ margin_by_zip.plot(kind='bar', color='orange')
54
+ elif chart_type == 'Scatter Plot':
55
+ plt.scatter(margin_by_zip.index, margin_by_zip.values, color='orange')
56
+ elif chart_type == 'Line Chart':
57
+ margin_by_zip.plot(kind='line', color='orange')
58
+ plt.title('Gross Margin by ZIP Code')
59
+ plt.xlabel('ZIP Code')
60
+ plt.ylabel('Gross Margin (%)')
61
+ plt.xticks(rotation=45)
62
+ st.pyplot(plt)
63
+
64
+
65
+ # Streamlit App
66
+ def main():
67
+ st.title("Sales and Cost Dashboard")
68
+
69
+ # Sidebar options
70
+ st.sidebar.title("Options")
71
+ options = st.sidebar.radio(
72
+ "Select a Report", [
73
+ 'Data Information',
74
+ 'Net Sales by ZIP Code',
75
+ 'Cost by ZIP Code',
76
+ 'Gross Profit by ZIP Code',
77
+ 'Gross Margin by ZIP Code',
78
+ 'Average Invoice by ZIP Code'
79
+ ]
80
+ )
81
+
82
+ chart_type = st.sidebar.selectbox("Select Chart Type", ['Bar Chart', 'Scatter Plot', 'Line Chart'])
83
+
84
+ if options == 'Data Information':
85
+ display_data_info(data)
86
+ elif options == 'Net Sales by ZIP Code':
87
+ plot_data(data, 'Net Sale', chart_type)
88
+ elif options == 'Cost by ZIP Code':
89
+ plot_data(data, 'Cost', chart_type)
90
+ elif options == 'Gross Profit by ZIP Code':
91
+ plot_data(data, 'Gross Profit', chart_type)
92
+ elif options == 'Gross Margin by ZIP Code':
93
+ gross_margin_by_zip_code(data, chart_type)
94
+ elif options == 'Average Invoice by ZIP Code':
95
+ plot_data(data, ' AVG Inv. ', chart_type)
96
+
97
+
98
+ if __name__ == '__main__':
99
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ matplotlib