Spaces:
Sleeping
Sleeping
Update pages/Hotel Data.py
Browse files- pages/Hotel Data.py +31 -17
pages/Hotel Data.py
CHANGED
|
@@ -1,29 +1,43 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
| 9 |
|
| 10 |
if uploaded_file is not None:
|
| 11 |
# Read the uploaded CSV file into a pandas DataFrame
|
| 12 |
df = pd.read_csv(uploaded_file)
|
| 13 |
|
| 14 |
-
# Save the
|
| 15 |
-
|
| 16 |
|
| 17 |
-
# Display the
|
| 18 |
-
st.subheader("Dataset Preview:")
|
| 19 |
-
st.write(df) # Display the first 5 rows
|
| 20 |
|
| 21 |
-
# Display
|
| 22 |
-
st.success("Dataset uploaded and saved
|
| 23 |
-
|
| 24 |
-
elif 'df' in st.session_state:
|
| 25 |
-
# If a dataset is already stored in session state
|
| 26 |
-
st.subheader("Dataset Preview (Previously Uploaded):")
|
| 27 |
-
st.write(st.session_state.df.head())
|
| 28 |
-
else:
|
| 29 |
-
st.info("Please upload a CSV file to see the dataset information.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Define a persistent file path for the dataset
|
| 6 |
+
DATA_FILE_PATH = "dataset.csv"
|
| 7 |
|
| 8 |
+
# Page Title
|
| 9 |
+
st.markdown("<h1 style='text-align:center; color:yellow;'>Hotel Data Set</h1>", unsafe_allow_html=True)
|
| 10 |
+
|
| 11 |
+
# Check if a dataset already exists on disk
|
| 12 |
+
if os.path.exists(DATA_FILE_PATH):
|
| 13 |
+
# If dataset exists, load it
|
| 14 |
+
df = pd.read_csv(DATA_FILE_PATH)
|
| 15 |
+
|
| 16 |
+
# Display dataset
|
| 17 |
+
st.subheader("Current Dataset (Previously Uploaded):")
|
| 18 |
+
st.write(df.head()) # Display the first 5 rows of the dataset
|
| 19 |
+
|
| 20 |
+
st.subheader("Dataset Description:")
|
| 21 |
+
st.write(df.describe())
|
| 22 |
+
|
| 23 |
+
st.subheader("Dataset Shape (Rows, Columns):")
|
| 24 |
+
st.write(df.shape)
|
| 25 |
+
else:
|
| 26 |
+
st.info("No dataset found. Please upload a CSV file.")
|
| 27 |
+
|
| 28 |
+
# File uploader widget to upload a new dataset
|
| 29 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
| 30 |
|
| 31 |
if uploaded_file is not None:
|
| 32 |
# Read the uploaded CSV file into a pandas DataFrame
|
| 33 |
df = pd.read_csv(uploaded_file)
|
| 34 |
|
| 35 |
+
# Save the dataset permanently to disk
|
| 36 |
+
df.to_csv(DATA_FILE_PATH, index=False)
|
| 37 |
|
| 38 |
+
# Display the uploaded dataset
|
| 39 |
+
st.subheader("Uploaded Dataset Preview:")
|
| 40 |
+
st.write(df.head()) # Display the first 5 rows
|
| 41 |
|
| 42 |
+
# Display success message
|
| 43 |
+
st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|