Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import streamlit as st
|
|
6 |
from wordcloud import WordCloud
|
7 |
import matplotlib.pyplot as plt
|
8 |
from collections import Counter
|
|
|
9 |
|
10 |
# Function to load data from SQLite database
|
11 |
def load_data(db_file):
|
@@ -145,8 +146,8 @@ def plot_movie_release_years(df_release_years):
|
|
145 |
|
146 |
# Function to plot global map of total films per region using Plotly Express
|
147 |
def plot_global_map():
|
148 |
-
# Country code to name mapping
|
149 |
df = pd.read_csv('movie_region.csv')
|
|
|
150 |
country_mapping = {
|
151 |
'AF': 'Afghanistan', 'AX': 'Åland Islands', 'AL': 'Albania', 'DZ': 'Algeria', 'AS': 'American Samoa',
|
152 |
'AD': 'Andorra', 'AO': 'Angola', 'AI': 'Anguilla', 'AQ': 'Antarctica', 'AG': 'Antigua and Barbuda',
|
@@ -164,42 +165,49 @@ def plot_global_map():
|
|
164 |
'FR': 'France', 'GA': 'Gabon', 'GM': 'Gambia', 'GE': 'Georgia', 'DE': 'Germany',
|
165 |
'GH': 'Ghana', 'GR': 'Greece', 'GD': 'Grenada', 'GT': 'Guatemala', 'GN': 'Guinea',
|
166 |
'GW': 'Guinea-Bissau', 'GY': 'Guyana', 'HT': 'Haiti', 'HN': 'Honduras', 'HK': 'Hong Kong',
|
167 |
-
'HU': 'Hungary', 'IS': 'Iceland', 'IN': 'India', 'ID': 'Indonesia', 'IR': 'Iran',
|
168 |
-
'IQ': 'Iraq', 'IE': 'Ireland', '
|
169 |
-
'
|
170 |
-
'
|
171 |
'LV': 'Latvia', 'LB': 'Lebanon', 'LS': 'Lesotho', 'LR': 'Liberia', 'LY': 'Libya',
|
172 |
-
'
|
173 |
'MG': 'Madagascar', 'MW': 'Malawi', 'MY': 'Malaysia', 'MV': 'Maldives', 'ML': 'Mali',
|
174 |
-
'MT': 'Malta', '
|
175 |
-
'
|
176 |
-
'
|
177 |
-
'
|
178 |
-
'
|
179 |
-
'
|
180 |
-
'
|
181 |
-
'
|
182 |
-
'
|
183 |
-
'
|
184 |
-
'
|
185 |
-
'
|
186 |
-
'
|
187 |
-
'SZ': 'Swaziland', 'SE': 'Sweden', 'CH': 'Switzerland', 'SY': 'Syria', 'TW': 'Taiwan',
|
188 |
-
'TJ': 'Tajikistan', 'TZ': 'Tanzania', 'TH': 'Thailand', 'TL': 'Timor-Leste', 'TG': 'Togo',
|
189 |
-
'TK': 'Tokelau', 'TO': 'Tonga', 'TT': 'Trinidad and Tobago', 'TN': 'Tunisia', 'TR': 'Turkey',
|
190 |
-
'TM': 'Turkmenistan', 'TV': 'Tuvalu', 'UG': 'Uganda', 'UA': 'Ukraine', 'AE': 'United Arab Emirates',
|
191 |
'GB': 'United Kingdom', 'US': 'United States', 'UY': 'Uruguay', 'UZ': 'Uzbekistan', 'VU': 'Vanuatu',
|
192 |
-
'
|
193 |
}
|
194 |
|
195 |
-
#
|
196 |
df['region'] = df['region'].map(country_mapping)
|
197 |
|
198 |
-
#
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
return fig
|
205 |
|
|
|
6 |
from wordcloud import WordCloud
|
7 |
import matplotlib.pyplot as plt
|
8 |
from collections import Counter
|
9 |
+
import numpy as np
|
10 |
|
11 |
# Function to load data from SQLite database
|
12 |
def load_data(db_file):
|
|
|
146 |
|
147 |
# Function to plot global map of total films per region using Plotly Express
|
148 |
def plot_global_map():
|
|
|
149 |
df = pd.read_csv('movie_region.csv')
|
150 |
+
# Country code to name mapping
|
151 |
country_mapping = {
|
152 |
'AF': 'Afghanistan', 'AX': 'Åland Islands', 'AL': 'Albania', 'DZ': 'Algeria', 'AS': 'American Samoa',
|
153 |
'AD': 'Andorra', 'AO': 'Angola', 'AI': 'Anguilla', 'AQ': 'Antarctica', 'AG': 'Antigua and Barbuda',
|
|
|
165 |
'FR': 'France', 'GA': 'Gabon', 'GM': 'Gambia', 'GE': 'Georgia', 'DE': 'Germany',
|
166 |
'GH': 'Ghana', 'GR': 'Greece', 'GD': 'Grenada', 'GT': 'Guatemala', 'GN': 'Guinea',
|
167 |
'GW': 'Guinea-Bissau', 'GY': 'Guyana', 'HT': 'Haiti', 'HN': 'Honduras', 'HK': 'Hong Kong',
|
168 |
+
'HU': 'Hungary', 'IS': 'Iceland', 'IN': 'India', 'ID': 'Indonesia', 'IR': 'Iran, Islamic Republic of',
|
169 |
+
'IQ': 'Iraq', 'IE': 'Ireland', 'IL': 'Israel', 'IT': 'Italy', 'JM': 'Jamaica',
|
170 |
+
'JP': 'Japan', 'JO': 'Jordan', 'KZ': 'Kazakhstan', 'KE': 'Kenya', 'KP': 'Korea, Democratic People\'s Republic of',
|
171 |
+
'KR': 'Korea, Republic of', 'KW': 'Kuwait', 'KG': 'Kyrgyzstan', 'LA': 'Lao People\'s Democratic Republic',
|
172 |
'LV': 'Latvia', 'LB': 'Lebanon', 'LS': 'Lesotho', 'LR': 'Liberia', 'LY': 'Libya',
|
173 |
+
'LT': 'Lithuania', 'LU': 'Luxembourg', 'MO': 'Macao', 'MK': 'Macedonia, the Former Yugoslav Republic of',
|
174 |
'MG': 'Madagascar', 'MW': 'Malawi', 'MY': 'Malaysia', 'MV': 'Maldives', 'ML': 'Mali',
|
175 |
+
'MT': 'Malta', 'MR': 'Mauritania', 'MU': 'Mauritius', 'MX': 'Mexico', 'MD': 'Moldova, Republic of',
|
176 |
+
'MN': 'Mongolia', 'ME': 'Montenegro', 'MA': 'Morocco', 'MZ': 'Mozambique', 'MM': 'Myanmar',
|
177 |
+
'NA': 'Namibia', 'NP': 'Nepal', 'NL': 'Netherlands', 'NZ': 'New Zealand', 'NI': 'Nicaragua',
|
178 |
+
'NE': 'Niger', 'NG': 'Nigeria', 'NO': 'Norway', 'OM': 'Oman', 'PK': 'Pakistan',
|
179 |
+
'PW': 'Palau', 'PA': 'Panama', 'PG': 'Papua New Guinea', 'PY': 'Paraguay', 'PE': 'Peru',
|
180 |
+
'PH': 'Philippines', 'PL': 'Poland', 'PT': 'Portugal', 'QA': 'Qatar', 'RO': 'Romania',
|
181 |
+
'RU': 'Russian Federation', 'RW': 'Rwanda', 'WS': 'Samoa', 'SA': 'Saudi Arabia', 'SN': 'Senegal',
|
182 |
+
'RS': 'Serbia', 'SL': 'Sierra Leone', 'SG': 'Singapore', 'SK': 'Slovakia', 'SI': 'Slovenia',
|
183 |
+
'SB': 'Solomon Islands', 'ZA': 'South Africa', 'ES': 'Spain', 'LK': 'Sri Lanka', 'SD': 'Sudan',
|
184 |
+
'SR': 'Suriname', 'SZ': 'Swaziland', 'SE': 'Sweden', 'CH': 'Switzerland', 'SY': 'Syrian Arab Republic',
|
185 |
+
'TW': 'Taiwan, Province of China', 'TJ': 'Tajikistan', 'TZ': 'Tanzania, United Republic of', 'TH': 'Thailand',
|
186 |
+
'TL': 'Timor-Leste', 'TG': 'Togo', 'TO': 'Tonga', 'TT': 'Trinidad and Tobago', 'TN': 'Tunisia',
|
187 |
+
'TR': 'Turkey', 'TM': 'Turkmenistan', 'UG': 'Uganda', 'UA': 'Ukraine', 'AE': 'United Arab Emirates',
|
|
|
|
|
|
|
|
|
188 |
'GB': 'United Kingdom', 'US': 'United States', 'UY': 'Uruguay', 'UZ': 'Uzbekistan', 'VU': 'Vanuatu',
|
189 |
+
'VE': 'Venezuela, Bolivarian Republic of', 'VN': 'Viet Nam', 'ZM': 'Zambia', 'ZW': 'Zimbabwe'
|
190 |
}
|
191 |
|
192 |
+
# Map country codes to country names
|
193 |
df['region'] = df['region'].map(country_mapping)
|
194 |
|
195 |
+
# Group by country and count the number of films
|
196 |
+
df_grouped = df.groupby('region').size().reset_index(name='total_films')
|
197 |
+
|
198 |
+
# Apply log transformation to handle outliers
|
199 |
+
df_grouped['log_total_films'] = np.log1p(df_grouped['total_films'])
|
200 |
+
|
201 |
+
# Create a choropleth map with the log-transformed data
|
202 |
+
fig = px.choropleth(df_grouped, locations='region', locationmode='country names',
|
203 |
+
color='log_total_films', hover_name='region',
|
204 |
+
color_continuous_scale='Plasma', # Change the color scheme here
|
205 |
+
labels={'log_total_films': 'Total Films (log scale)'})
|
206 |
+
|
207 |
+
# Update layout of the map
|
208 |
+
fig.update_layout(title='Total Films by Country (Log Scale)',
|
209 |
+
geo=dict(showframe=False, showcoastlines=False,
|
210 |
+
projection_type='equirectangular'))
|
211 |
|
212 |
return fig
|
213 |
|