import streamlit as st
import pandas as pd
import os
import re
import preprocessor as p
import joblib
import base64
project_description = """
# Hotel Data Analysis Project
## Overview
I have completed a hotel data analysis project using an instant web scraper.
This project involved scraping hotel data and hotel reviews separately, cleaning the data,
concatenating it, and performing sentiment analysis on the DataFrame.
Additionally, I clustered the hotel reviews, applied sentiment analysis, and passed
those clusters to an LLM (Language Model) to extract strengths and weaknesses of hotels.
## Steps
### 1. Scraping Hotel Data
- Utilized an instant web scraper to collect hotel data.
- Scraped hotel data separately from hotel reviews.
### 2. Data Collection
- Collected hotel data and hotel reviews data separately for each hotel.
### 3. Data Cleaning
- Cleaned the collected data to remove any inconsistencies or errors.
- Applied preprocessing techniques to prepare the data for analysis.
### 4. Data Concatenation
- Concatenated the cleaned hotel data and hotel reviews data to create a unified dataset for analysis.
### 5. Sentiment Analysis
- Performed sentiment analysis on the concatenated DataFrame.
- Utilized the results to understand the overall sentiment of hotel reviews.
### 6. Clustering Hotel Reviews
- Clustered the hotel reviews based on their content to identify patterns and similarities.
### 7. Extracting Strengths and Weaknesses
- Passed the clustered reviews to an LLM (Language Model) to extract strengths and weaknesses of hotels.
- Used the extracted information to gain insights into customer perceptions.
## Conclusion
This project demonstrates the use of web scraping, data cleaning, sentiment analysis, and clustering techniques to analyze hotel data.
The extracted strengths and weaknesses provide valuable insights for hotel management to improve customer satisfaction and service quality.
"""
def create_download_link(df, filename):
csv = df.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
href = f'Download CSV file'
return href
# Path to the directory containing CSV files
directory_path = r'hotel reviews'
# Get a list of CSV files in the directory
csv_files = [file for file in os.listdir(directory_path) if file.endswith('.csv')]
# Function to concatenate selected columns
def concatenate_columns(df, selected_columns):
concatenated_data = df[selected_columns[0]].tolist() + df[selected_columns[1]].tolist()
return pd.DataFrame({'ConcatenatedData': concatenated_data})
# Function to display selected dataset
def display_selected_dataset(selected_dataset):
dataset_path = os.path.join(directory_path, selected_dataset)
selected_df = pd.read_csv(dataset_path)
st.subheader(f'Dataset: {selected_dataset}')
st.write(selected_df)
def clean_tweets(series):
REPLACE_NO_SPACE = re.compile("[.;:!\'?,\"()\[\]]")
REPLACE_WITH_SPACE = re.compile("(
)|(\-)|(\/)")
tempArr = []
for line in series:
# Check if the value is NaN
if pd.isnull(line):
tempArr.append("")
continue
# Send to tweet_processor
tmpL = p.clean(line)
# Remove punctuation
tmpL = REPLACE_NO_SPACE.sub("", tmpL.lower())
# Replace specific characters with spaces
tmpL = REPLACE_WITH_SPACE.sub(" ", tmpL)
# Remove extra spaces
tmpL = " ".join(tmpL.split())
tempArr.append(tmpL)
return tempArr
# Streamlit app
def main():
# Create a menu bar
menu = st.sidebar.selectbox(
'Navigation',
['Home', 'collected hotel data', 'Display Hotel Data', 'Display hotel reviews Datasets']
)
if menu == 'Home':
st.markdown(project_description)
elif menu == 'collected hotel data':
# Display DataFrame
df = pd.read_csv('chennai hotes.csv')
df1 = pd.read_csv('stream.csv')
st.subheader('Collected chennai hotes Data')
st.write(df)
st.subheader('preprocess applyed data')
st.write(df1)
elif menu == 'Display Hotel Data':
# Display hotel data
df = pd.read_csv('stream.csv')
css = """
"""
st.markdown(css, unsafe_allow_html=True)
for index, row in df.iterrows():
st.markdown(f"""
Rating: {row['rating']}
Location: {row['location']} ({row['nearest places']})
Website: Website link
Number of Reviews: {row['number of reviewss 2']}
Room Type: {row['room type']}
Price: {row['price']}
Strengths: {row['Strengths']}
Weaknesses: {row['Weaknesses']}