mirror of
https://github.com/aykhans/IMDBDataVisualization.git
synced 2025-04-21 09:03:27 +00:00
V 1.0.2
This commit is contained in:
parent
396cd8916d
commit
733d155863
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
38
app/app.py
Normal file
38
app/app.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import plotly.express as px
|
||||||
|
from collections import Counter
|
||||||
|
import streamlit as st
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
|
||||||
|
class App():
|
||||||
|
def __init__(self, page_title: str, page_icon: str, layout: str) -> None:
|
||||||
|
self.st = st
|
||||||
|
self.st.set_page_config(page_title=page_title, page_icon=page_icon, layout=layout)
|
||||||
|
|
||||||
|
def getDataGenresCount(self, data: pd.DataFrame, genres_type: str) -> Counter:
|
||||||
|
if genres_type == 'Movie':
|
||||||
|
data = data.query("Title_Type == 'movie' or Title_Type == 'tvMovie'")
|
||||||
|
elif genres_type == 'Series':
|
||||||
|
data = data.query("Title_Type == 'tvSeries' or Title_Type == 'tvMiniSeries'")
|
||||||
|
|
||||||
|
data_genres = pd.DataFrame({'title': data['Title'], 'genres': data['Genres']})
|
||||||
|
|
||||||
|
genres = []
|
||||||
|
for i in data_genres['genres']:
|
||||||
|
genres += i.replace(' ', '').split(',')
|
||||||
|
genres_count = Counter(genres)
|
||||||
|
return genres_count
|
||||||
|
|
||||||
|
def createPieChart(self, data: pd.DataFrame, genres_type: str, selected_genres: List[str]):
|
||||||
|
genres_count = self.getDataGenresCount(data, genres_type)
|
||||||
|
df = pd.DataFrame({'title': genres_count.keys(), 'count': genres_count.values()}).\
|
||||||
|
query('title == @selected_genres')
|
||||||
|
pie_chart = px.pie(df, names='title', values='count', title=genres_type + ' genres')
|
||||||
|
return pie_chart
|
||||||
|
|
||||||
|
def preprocessingData(self, upload_file: str) -> Optional[pd.DataFrame]:
|
||||||
|
if upload_file is not None:
|
||||||
|
data = pd.read_csv(upload_file)
|
||||||
|
data.rename(columns = {'Title Type': 'Title_Type'}, inplace = True)
|
||||||
|
return data
|
73
app/main.py
73
app/main.py
@ -1,51 +1,32 @@
|
|||||||
|
from app import App
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.express as px
|
|
||||||
from collections import Counter
|
|
||||||
import streamlit as st
|
|
||||||
|
|
||||||
|
|
||||||
st.set_page_config(page_title='Dashboard',
|
class Main():
|
||||||
page_icon=':bar_chart:',
|
def __init__(self):
|
||||||
layout='wide')
|
self.app = App(page_title='Dashboard', page_icon=':bar_chart:', layout='wide')
|
||||||
|
data = self.uploadFile()
|
||||||
|
selected_genres = self.sideBar(data)
|
||||||
|
if data is not None:
|
||||||
|
self.app.st.plotly_chart(self.app.createPieChart(data, 'All', selected_genres))
|
||||||
|
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Movie', selected_genres))
|
||||||
|
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Series'))
|
||||||
|
|
||||||
|
def sideBar(self, data: pd.DataFrame):
|
||||||
|
data = self.app.getDataGenresCount(data, 'all')
|
||||||
|
self.app.st.sidebar.header('Data by Genre:')
|
||||||
|
data_genre_filter = self.app.st.sidebar.multiselect(
|
||||||
|
'Select Genre:',
|
||||||
|
options = data.keys(),
|
||||||
|
default = data.keys()
|
||||||
|
)
|
||||||
|
|
||||||
|
return data_genre_filter
|
||||||
|
|
||||||
|
def uploadFile(self) -> pd.DataFrame:
|
||||||
|
uploaded_file = 'app\\WATCHLIST.csv' # app.st.file_uploader("Choose a file")
|
||||||
|
data = self.app.preprocessingData(uploaded_file)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
uploaded_file = 'app\\WATCHLIST.csv' # st.file_uploader("Choose a file")
|
if __name__ == '__main__': Main()
|
||||||
|
|
||||||
if uploaded_file is not None:
|
|
||||||
data = pd.read_csv(uploaded_file)
|
|
||||||
|
|
||||||
data.rename(columns = {'Title Type': 'Title_Type'}, inplace = True)
|
|
||||||
|
|
||||||
# ======================================== All ========================================
|
|
||||||
|
|
||||||
data_all = pd.DataFrame({'title': data['Title'], 'genres': data['Genres']})
|
|
||||||
|
|
||||||
genres_all = []
|
|
||||||
for i in data_all['genres']:
|
|
||||||
genres_all += i.replace(' ', '').split(',')
|
|
||||||
genres_all_count = Counter(genres_all)
|
|
||||||
|
|
||||||
# ======================================== tvSeries, tvMiniSeries ========================================
|
|
||||||
|
|
||||||
data_series = data.query("Title_Type == 'tvSeries' or Title_Type == 'tvMiniSeries'")
|
|
||||||
data_series = pd.DataFrame({'title': data_series['Title'], 'genres': data_series['Genres']})
|
|
||||||
|
|
||||||
genres_series = []
|
|
||||||
for i in data_series['genres']:
|
|
||||||
genres_series += i.replace(' ', '').split(',')
|
|
||||||
genres_series_count = Counter(genres_series)
|
|
||||||
|
|
||||||
# ======================================== movie, tvMovie ========================================
|
|
||||||
|
|
||||||
data_movie = data.query("Title_Type == 'movie' or Title_Type == 'tvMovie'")
|
|
||||||
data_movie = pd.DataFrame({'title': data_movie['Title'], 'genres': data_movie['Genres']})
|
|
||||||
|
|
||||||
genres_movie = []
|
|
||||||
for i in data_movie['genres']:
|
|
||||||
genres_movie += i.replace(' ', '').split(',')
|
|
||||||
genres_movie_count = Counter(genres_movie)
|
|
||||||
|
|
||||||
genres_all_pie_chart = px.pie(pd.DataFrame({'title': genres_all_count.keys(), 'count': genres_all_count.values()}),
|
|
||||||
names='title', values='count', title='All genres')
|
|
||||||
|
|
||||||
st.plotly_chart(genres_all_pie_chart)
|
|
Loading…
x
Reference in New Issue
Block a user