Update pages/1_Data_Card_and_Data_collection.py
Browse files
pages/1_Data_Card_and_Data_collection.py
CHANGED
|
@@ -9,14 +9,14 @@ DATA_FILE_PATH = "consumer_electronics_sales_data.csv"
|
|
| 9 |
# Page Title
|
| 10 |
st.markdown("<h1 style='text-align:center; color:white;'>Electronics Sales Data Set</h1>", unsafe_allow_html=True)
|
| 11 |
|
| 12 |
-
# Function to load the dataset
|
| 13 |
def load_dataset():
|
| 14 |
if os.path.exists(DATA_FILE_PATH):
|
| 15 |
return pd.read_csv(DATA_FILE_PATH)
|
| 16 |
else:
|
| 17 |
return None
|
| 18 |
|
| 19 |
-
#
|
| 20 |
if "dataset" not in st.session_state:
|
| 21 |
st.session_state["dataset"] = load_dataset()
|
| 22 |
|
|
@@ -30,7 +30,7 @@ if uploaded_file is not None:
|
|
| 30 |
# Save the dataset permanently to disk
|
| 31 |
df.to_csv(DATA_FILE_PATH, index=False)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
st.session_state["dataset"] = df
|
| 35 |
|
| 36 |
# Display success message
|
|
@@ -41,24 +41,18 @@ df = st.session_state.get("dataset")
|
|
| 41 |
|
| 42 |
if df is not None:
|
| 43 |
st.subheader("Dataset Preview:")
|
| 44 |
-
|
| 45 |
-
st.write(df, use_container_width=True) # Set to use container width
|
| 46 |
|
| 47 |
st.subheader("Info of the Dataset:")
|
| 48 |
-
# Redirect the output of df.info() to a string buffer
|
| 49 |
buffer = StringIO()
|
| 50 |
df.info(buf=buffer)
|
| 51 |
-
|
| 52 |
-
# Display the content in Streamlit
|
| 53 |
st.text(buffer.getvalue())
|
| 54 |
|
| 55 |
st.subheader("Dataset Shape (Rows, Columns):")
|
| 56 |
st.write(df.shape)
|
| 57 |
else:
|
| 58 |
st.info("No dataset found. Please upload a CSV file.")
|
| 59 |
-
|
| 60 |
-
# About the Dataset section with left alignment and larger font
|
| 61 |
-
st.markdown('''
|
| 62 |
# About the Dataset
|
| 63 |
## Description:
|
| 64 |
This dataset provides insights into consumer electronics sales, featuring product categories, brands, prices, customer demographics, purchase behavior, and satisfaction metrics. It aims to analyze factors influencing purchase intent and customer satisfaction in the consumer electronics market.
|
|
@@ -98,17 +92,17 @@ st.markdown(
|
|
| 98 |
left: 0;
|
| 99 |
width: 100%;
|
| 100 |
height: 100%;
|
| 101 |
-
background: rgba(0, 0, 0, 0.4);
|
| 102 |
z-index: -1;
|
| 103 |
}}
|
| 104 |
|
| 105 |
/* Styling the content to ensure text visibility */
|
| 106 |
.stMarkdown {{
|
| 107 |
color: white;
|
| 108 |
-
font-size: 25px;
|
| 109 |
-
text-align: left;
|
| 110 |
-
width: 90%;
|
| 111 |
-
margin: 0 auto;
|
| 112 |
}}
|
| 113 |
|
| 114 |
/* Center align the dataset and info */
|
|
@@ -118,5 +112,5 @@ st.markdown(
|
|
| 118 |
}}
|
| 119 |
</style>
|
| 120 |
""",
|
| 121 |
-
unsafe_allow_html=True
|
| 122 |
)
|
|
|
|
| 9 |
# Page Title
|
| 10 |
st.markdown("<h1 style='text-align:center; color:white;'>Electronics Sales Data Set</h1>", unsafe_allow_html=True)
|
| 11 |
|
| 12 |
+
# Function to load the dataset from the disk
|
| 13 |
def load_dataset():
|
| 14 |
if os.path.exists(DATA_FILE_PATH):
|
| 15 |
return pd.read_csv(DATA_FILE_PATH)
|
| 16 |
else:
|
| 17 |
return None
|
| 18 |
|
| 19 |
+
# Load the dataset into session state if not already done
|
| 20 |
if "dataset" not in st.session_state:
|
| 21 |
st.session_state["dataset"] = load_dataset()
|
| 22 |
|
|
|
|
| 30 |
# Save the dataset permanently to disk
|
| 31 |
df.to_csv(DATA_FILE_PATH, index=False)
|
| 32 |
|
| 33 |
+
# Update session state
|
| 34 |
st.session_state["dataset"] = df
|
| 35 |
|
| 36 |
# Display success message
|
|
|
|
| 41 |
|
| 42 |
if df is not None:
|
| 43 |
st.subheader("Dataset Preview:")
|
| 44 |
+
st.write(df, use_container_width=True)
|
|
|
|
| 45 |
|
| 46 |
st.subheader("Info of the Dataset:")
|
|
|
|
| 47 |
buffer = StringIO()
|
| 48 |
df.info(buf=buffer)
|
|
|
|
|
|
|
| 49 |
st.text(buffer.getvalue())
|
| 50 |
|
| 51 |
st.subheader("Dataset Shape (Rows, Columns):")
|
| 52 |
st.write(df.shape)
|
| 53 |
else:
|
| 54 |
st.info("No dataset found. Please upload a CSV file.")
|
| 55 |
+
st.markdown('''
|
|
|
|
|
|
|
| 56 |
# About the Dataset
|
| 57 |
## Description:
|
| 58 |
This dataset provides insights into consumer electronics sales, featuring product categories, brands, prices, customer demographics, purchase behavior, and satisfaction metrics. It aims to analyze factors influencing purchase intent and customer satisfaction in the consumer electronics market.
|
|
|
|
| 92 |
left: 0;
|
| 93 |
width: 100%;
|
| 94 |
height: 100%;
|
| 95 |
+
background: rgba(0, 0, 0, 0.4);
|
| 96 |
z-index: -1;
|
| 97 |
}}
|
| 98 |
|
| 99 |
/* Styling the content to ensure text visibility */
|
| 100 |
.stMarkdown {{
|
| 101 |
color: white;
|
| 102 |
+
font-size: 25px;
|
| 103 |
+
text-align: left;
|
| 104 |
+
width: 90%;
|
| 105 |
+
margin: 0 auto;
|
| 106 |
}}
|
| 107 |
|
| 108 |
/* Center align the dataset and info */
|
|
|
|
| 112 |
}}
|
| 113 |
</style>
|
| 114 |
""",
|
| 115 |
+
unsafe_allow_html=True
|
| 116 |
)
|