shilpabanerjee commited on
Commit
ea07a54
·
1 Parent(s): 5fe838f

Upload 3 files

Browse files
Files changed (3) hide show
  1. amazon.csv +0 -0
  2. app.py +81 -0
  3. reuirements.txt +5 -0
amazon.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ from sklearn.linear_model import LinearRegression
6
+ import re
7
+
8
+ # Load the CSV file
9
+ data = pd.read_csv('amazon.csv', delimiter=',')
10
+
11
+ # Function to extract numeric values from a string (remove non-numeric characters)
12
+ def extract_numeric_value(value):
13
+ numeric_value = re.sub(r'[^\d.]', '', value)
14
+ return float(numeric_value) if numeric_value else None
15
+
16
+ # Convert 'actual_price' and 'rating' columns to numeric by removing non-numeric characters
17
+ data['actual_price'] = data['actual_price'].apply(extract_numeric_value)
18
+ data['rating'] = data['rating'].apply(extract_numeric_value)
19
+
20
+ # Title
21
+ st.title('Sales Forecasting and Product Analysis')
22
+
23
+ # Sidebar filters
24
+ category_filter = st.sidebar.selectbox('Select Category', data['category'].unique())
25
+ product_filter = st.sidebar.selectbox('Select Product', data[data['category'] == category_filter]['product_name'].unique())
26
+
27
+ filtered_data = data[(data['category'] == category_filter) & (data['product_name'] == product_filter)]
28
+
29
+ # Display basic product information
30
+ st.subheader('Product Information')
31
+ st.write('Product ID:', filtered_data['product_id'].values[0])
32
+ st.write('Product Name:', product_filter)
33
+ st.write('Category:', category_filter)
34
+ st.write('Discounted Price:', filtered_data['discounted_price'].values[0])
35
+ st.write('Actual Price:', filtered_data['actual_price'].values[0])
36
+ st.write('Discount Percentage:', filtered_data['discount_percentage'].values[0])
37
+ st.write('Average Rating:', filtered_data['rating'].mean())
38
+ st.write('Rating Count:', filtered_data['rating_count'].values[0])
39
+ st.write('About Product:', filtered_data['about_product'].values[0])
40
+
41
+
42
+ # Display product image
43
+ product_image_url = filtered_data['img_link'].values[0]
44
+ st.image(product_image_url, caption='Product Image', use_column_width=True)
45
+
46
+
47
+ # Cumulative sales plot over rows (assumes rows are ordered chronologically)
48
+ cumulative_sales_over_rows = filtered_data.index + 1
49
+ st.subheader('Cumulative Sales Over Rows')
50
+ fig, ax = plt.subplots(figsize=(10, 6))
51
+ ax.plot(cumulative_sales_over_rows, filtered_data['actual_price'].cumsum())
52
+ ax.set_xlabel('Rows')
53
+ ax.set_ylabel('Cumulative Sales')
54
+ st.pyplot(fig)
55
+
56
+ # Sales forecasting using Linear Regression
57
+ st.subheader('Sales Forecasting')
58
+ forecast_days = st.number_input('Enter the number of days for sales forecasting:', min_value=1, value=7)
59
+
60
+ # Convert the row index to numeric values
61
+ row_numeric = cumulative_sales_over_rows.values.reshape(-1, 1)
62
+ X = row_numeric
63
+ y = filtered_data['actual_price'].cumsum().values
64
+ model = LinearRegression()
65
+ model.fit(X, y)
66
+
67
+ # Generate future row indices for forecasting
68
+ last_row = cumulative_sales_over_rows.max()
69
+ forecast_rows = [last_row + i for i in range(1, forecast_days + 1)]
70
+ forecast_rows_numeric = pd.Series(forecast_rows).values.reshape(-1, 1)
71
+
72
+ # Predict cumulative sales for forecasted rows
73
+ forecast_values = model.predict(forecast_rows_numeric)
74
+ forecast_cumulative_sales = forecast_values
75
+
76
+ forecast_df = pd.DataFrame({'Row': forecast_rows, 'Forecasted Cumulative Sales': forecast_cumulative_sales})
77
+ st.write(forecast_df)
78
+
79
+
80
+ # Footer
81
+ st.text('Data Used: Amazon Sales Data')
reuirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit==0.87.0
2
+ pandas==1.3.3
3
+ matplotlib==3.4.3
4
+ seaborn==0.11.2
5
+ scikit-learn==0.24.2