Spaces:
Sleeping
Sleeping
Yunus Serhat Bıçakçı
commited on
Commit
·
3345323
1
Parent(s):
51129a6
update
Browse files- pages/4_Test.py +45 -0
pages/4_Test.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import folium
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
boroughs_count_2022_dec_df = "https://raw.githubusercontent.com/yunusserhat/data/main/data/boroughs_count_df_2022_dec.geojson"
|
| 6 |
+
mps_hate_2022_dec_df = "https://raw.githubusercontent.com/yunusserhat/data/main/data/mps_hate_2022_dec_count.geojson"
|
| 7 |
+
|
| 8 |
+
# Merging the datasets based on boroughs
|
| 9 |
+
merged_df = pd.merge(boroughs_count_2022_dec_df[['geo.name', 'count']],
|
| 10 |
+
mps_hate_2022_dec_df[['borough', 'Hate_Crime_Number']],
|
| 11 |
+
left_on='geo.name', right_on='borough')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Initialize the map centered around London
|
| 15 |
+
m = folium.Map(location=[51.5074, -0.1278], zoom_start=10)
|
| 16 |
+
|
| 17 |
+
boroughs_count_2022_dec_df = "https://raw.githubusercontent.com/yunusserhat/data/main/data/boroughs_count_df_2022_dec.geojson"
|
| 18 |
+
|
| 19 |
+
# Choropleth map for Hate Tweets by Borough
|
| 20 |
+
folium.Choropleth(
|
| 21 |
+
geo_data=boroughs_count_2022_dec_df,
|
| 22 |
+
data=boroughs_count_2022_dec_df,
|
| 23 |
+
columns=["geo.name", "count"],
|
| 24 |
+
key_on="feature.properties.geo.name",
|
| 25 |
+
fill_color="YlOrRd",
|
| 26 |
+
fill_opacity=0.7,
|
| 27 |
+
line_opacity=0.2,
|
| 28 |
+
legend_name="Number of Hate Tweets by Borough",
|
| 29 |
+
name="Hate Tweets",
|
| 30 |
+
highlight=True
|
| 31 |
+
).add_to(m)
|
| 32 |
+
|
| 33 |
+
# Adding popups to each borough
|
| 34 |
+
for idx, row in boroughs_count_2022_dec_df.iterrows():
|
| 35 |
+
popup_content = f"<strong>{row['geo.name']}</strong><br>Number of Hate Tweets: {row['count']}"
|
| 36 |
+
folium.Popup(popup_content).add_to(
|
| 37 |
+
folium.GeoJson(row['geometry']).add_to(m)
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Adding a layer control
|
| 41 |
+
folium.LayerControl().add_to(m)
|
| 42 |
+
|
| 43 |
+
# Displaying the map
|
| 44 |
+
m.to_streamlit()
|
| 45 |
+
|