Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ Interactive Streamlit app to explore the Île-de-France footballers dataset.
|
|
| 7 |
import streamlit as st
|
| 8 |
import pandas as pd
|
| 9 |
import plotly.express as px
|
|
|
|
| 10 |
from datasets import load_dataset
|
| 11 |
|
| 12 |
# Page config
|
|
@@ -267,22 +268,16 @@ def main():
|
|
| 267 |
year_counts = filtered_df['birth_year'].value_counts().sort_index()
|
| 268 |
|
| 269 |
if len(year_counts) > 0:
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
'Birth Year': [int(y) for y in year_counts.index],
|
| 273 |
-
'Number of Players': [int(c) for c in year_counts.values]
|
| 274 |
-
})
|
| 275 |
|
| 276 |
-
fig =
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
y='Number of Players',
|
| 280 |
-
color='Number of Players',
|
| 281 |
-
color_continuous_scale='Greens'
|
| 282 |
-
)
|
| 283 |
fig.update_layout(
|
|
|
|
|
|
|
| 284 |
height=350,
|
| 285 |
-
coloraxis_showscale=False,
|
| 286 |
plot_bgcolor='rgba(0,0,0,0)',
|
| 287 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 288 |
xaxis=dict(tickmode='linear', dtick=5)
|
|
@@ -345,30 +340,36 @@ def main():
|
|
| 345 |
if map_data:
|
| 346 |
map_df = pd.DataFrame(map_data)
|
| 347 |
|
| 348 |
-
#
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
map_df,
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
| 367 |
fig.update_layout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
height=500,
|
| 369 |
margin={'r': 0, 't': 0, 'l': 0, 'b': 0}
|
| 370 |
)
|
| 371 |
-
fig.update_traces(marker=dict(sizemin=10)) # Minimum marker size
|
| 372 |
st.plotly_chart(fig, use_container_width=True)
|
| 373 |
else:
|
| 374 |
st.info("No geographic data for current filters")
|
|
|
|
| 7 |
import streamlit as st
|
| 8 |
import pandas as pd
|
| 9 |
import plotly.express as px
|
| 10 |
+
import plotly.graph_objects as go
|
| 11 |
from datasets import load_dataset
|
| 12 |
|
| 13 |
# Page config
|
|
|
|
| 268 |
year_counts = filtered_df['birth_year'].value_counts().sort_index()
|
| 269 |
|
| 270 |
if len(year_counts) > 0:
|
| 271 |
+
years = [int(y) for y in year_counts.index]
|
| 272 |
+
counts = [int(c) for c in year_counts.values]
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
+
fig = go.Figure(data=[
|
| 275 |
+
go.Bar(x=years, y=counts, marker_color='green')
|
| 276 |
+
])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
fig.update_layout(
|
| 278 |
+
xaxis_title='Birth Year',
|
| 279 |
+
yaxis_title='Number of Players',
|
| 280 |
height=350,
|
|
|
|
| 281 |
plot_bgcolor='rgba(0,0,0,0)',
|
| 282 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 283 |
xaxis=dict(tickmode='linear', dtick=5)
|
|
|
|
| 340 |
if map_data:
|
| 341 |
map_df = pd.DataFrame(map_data)
|
| 342 |
|
| 343 |
+
# Scale marker sizes (min 15, max 60)
|
| 344 |
+
max_count = map_df['count'].max()
|
| 345 |
+
sizes = [max(15, int(40 * c / max_count) + 15) for c in map_df['count']]
|
| 346 |
+
|
| 347 |
+
fig = go.Figure(go.Scattermapbox(
|
| 348 |
+
lat=map_df['lat'].tolist(),
|
| 349 |
+
lon=map_df['lon'].tolist(),
|
| 350 |
+
mode='markers',
|
| 351 |
+
marker=go.scattermapbox.Marker(
|
| 352 |
+
size=sizes,
|
| 353 |
+
color=map_df['count'].tolist(),
|
| 354 |
+
colorscale='Reds',
|
| 355 |
+
showscale=True,
|
| 356 |
+
colorbar=dict(title='Players')
|
| 357 |
+
),
|
| 358 |
+
text=map_df['name'].tolist(),
|
| 359 |
+
hoverinfo='text+name',
|
| 360 |
+
customdata=map_df['count'].tolist(),
|
| 361 |
+
hovertemplate='%{text}<br>Players: %{customdata}<extra></extra>'
|
| 362 |
+
))
|
| 363 |
+
|
| 364 |
fig.update_layout(
|
| 365 |
+
mapbox=dict(
|
| 366 |
+
style='carto-positron',
|
| 367 |
+
center=dict(lat=48.85, lon=2.35),
|
| 368 |
+
zoom=9
|
| 369 |
+
),
|
| 370 |
height=500,
|
| 371 |
margin={'r': 0, 't': 0, 'l': 0, 'b': 0}
|
| 372 |
)
|
|
|
|
| 373 |
st.plotly_chart(fig, use_container_width=True)
|
| 374 |
else:
|
| 375 |
st.info("No geographic data for current filters")
|