Spaces:
Runtime error
Runtime error
add continent graph
Browse files- data.py +54 -0
- data_processing.py +16 -4
- stream_app.py +35 -18
data.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
countries = {'fr': 'france',
|
| 2 |
+
'us': 'united states',
|
| 3 |
+
'usa': 'united states',
|
| 4 |
+
'uk': 'united kingdom',
|
| 5 |
+
'ge': 'germany'}
|
| 6 |
+
|
| 7 |
+
country_ref = {
|
| 8 |
+
'france': 'europe',
|
| 9 |
+
'ireland': 'europe',
|
| 10 |
+
'luxembourg': 'europe',
|
| 11 |
+
'japan': 'asia',
|
| 12 |
+
'germany': 'europe',
|
| 13 |
+
'united states': 'north america',
|
| 14 |
+
'netherlands': 'europe',
|
| 15 |
+
'italy': 'europe', 'switzerland': 'europe',
|
| 16 |
+
'brazil': 'south america',
|
| 17 |
+
'sweden': 'europe',
|
| 18 |
+
'venezuela': 'south america', 'spain': 'europe', 'norway': 'europe', 'finland': 'europe',
|
| 19 |
+
'panama': 'south america',
|
| 20 |
+
'united kingdom': 'europe',
|
| 21 |
+
'denmark': 'europe',
|
| 22 |
+
'australia': 'australia',
|
| 23 |
+
'cayman islands': 'north america',
|
| 24 |
+
'saudi arabia': 'asia',
|
| 25 |
+
'hungary': 'europe',
|
| 26 |
+
'belgium': 'europe',
|
| 27 |
+
'iran (islamic republic of)': 'asia',
|
| 28 |
+
'canada': 'north america',
|
| 29 |
+
'morocco': 'africa',
|
| 30 |
+
'luxemburg': 'europe',
|
| 31 |
+
'liechtenstein': 'europe',
|
| 32 |
+
'curacao': 'south america',
|
| 33 |
+
'russia': 'europe',
|
| 34 |
+
'hong-kong': 'asia',
|
| 35 |
+
'albania': 'europe',
|
| 36 |
+
'chile': 'south america',
|
| 37 |
+
'china': 'asia',
|
| 38 |
+
'south korea': 'asia',
|
| 39 |
+
'israel': 'asia',
|
| 40 |
+
'taiwan': 'asia',
|
| 41 |
+
'singapore': 'asia',
|
| 42 |
+
'austria': 'europe',
|
| 43 |
+
'china (mainland)': 'asia',
|
| 44 |
+
'hong kong': 'asia',
|
| 45 |
+
'british virgin islands': 'europe',
|
| 46 |
+
'dubai': 'asia',
|
| 47 |
+
'ecuador': 'south america',
|
| 48 |
+
'korea': 'asia',
|
| 49 |
+
'mexico': 'south america',
|
| 50 |
+
'saoudi arabia': 'asia',
|
| 51 |
+
'indonesia': 'asia',
|
| 52 |
+
'united arab emirates': 'asia',
|
| 53 |
+
'seychelles': 'africa',
|
| 54 |
+
'costa rica': 'south america'}
|
data_processing.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
# util functions
|
|
@@ -52,22 +55,31 @@ def process_data(data):
|
|
| 52 |
# work on organisations
|
| 53 |
organizations = pd.DataFrame(data['organizations'])
|
| 54 |
organizations['id'] = organizations.url.apply(get_id)
|
|
|
|
| 55 |
organizations = organizations[["id", "name", "company_type", "revenues", "currency", "country", "lei"]]
|
|
|
|
| 56 |
organizations.columns = ['org_' + col for col in organizations.columns]
|
| 57 |
decisions = decisions.merge(organizations, left_on='organizations', right_on='org_id')
|
| 58 |
-
|
| 59 |
# remove Individual
|
| 60 |
decisions = decisions[decisions.org_company_type != "Individual"]
|
| 61 |
-
decisions.org_country = decisions.org_country.str.lower().str.strip()
|
| 62 |
|
| 63 |
# work on authorities
|
| 64 |
authorities = pd.DataFrame(data['authorities'])
|
| 65 |
authorities.index = authorities.url.apply(get_id)
|
| 66 |
authorities = authorities[["country", "type", "name"]]
|
| 67 |
-
|
| 68 |
-
authorities.country = authorities.country.apply(lambda v: countries.get(v, v)).str.lower().str.strip()
|
| 69 |
|
| 70 |
decisions['authorities_name'] = decisions.authorities.apply(replace_lis_val(authorities, 'name'))
|
| 71 |
decisions['authorities_country'] = decisions.authorities.apply(replace_lis_val(authorities, 'country')).apply(mode)
|
| 72 |
|
| 73 |
return decisions, organizations, authorities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from data import countries, country_ref
|
| 7 |
|
| 8 |
|
| 9 |
# util functions
|
|
|
|
| 55 |
# work on organisations
|
| 56 |
organizations = pd.DataFrame(data['organizations'])
|
| 57 |
organizations['id'] = organizations.url.apply(get_id)
|
| 58 |
+
organizations.country = organizations.country.str.lower().str.strip().apply(lambda v: countries.get(v, v))
|
| 59 |
organizations = organizations[["id", "name", "company_type", "revenues", "currency", "country", "lei"]]
|
| 60 |
+
organizations['continent'] = organizations.country.apply(lambda v: country_ref.get(v,v))
|
| 61 |
organizations.columns = ['org_' + col for col in organizations.columns]
|
| 62 |
decisions = decisions.merge(organizations, left_on='organizations', right_on='org_id')
|
|
|
|
| 63 |
# remove Individual
|
| 64 |
decisions = decisions[decisions.org_company_type != "Individual"]
|
|
|
|
| 65 |
|
| 66 |
# work on authorities
|
| 67 |
authorities = pd.DataFrame(data['authorities'])
|
| 68 |
authorities.index = authorities.url.apply(get_id)
|
| 69 |
authorities = authorities[["country", "type", "name"]]
|
| 70 |
+
authorities.country = authorities.country.str.lower().str.strip().apply(lambda v: countries.get(v, v))
|
|
|
|
| 71 |
|
| 72 |
decisions['authorities_name'] = decisions.authorities.apply(replace_lis_val(authorities, 'name'))
|
| 73 |
decisions['authorities_country'] = decisions.authorities.apply(replace_lis_val(authorities, 'country')).apply(mode)
|
| 74 |
|
| 75 |
return decisions, organizations, authorities
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def get_monetary_dataframe(decision_scope):
|
| 79 |
+
monetary_decision = decision_scope[decision_scope.monetary_sanction > 0]
|
| 80 |
+
monetary_decision = monetary_decision[monetary_decision.org_revenues != ""]
|
| 81 |
+
monetary_decision['org_revenues'] = monetary_decision.org_revenues.astype(float)
|
| 82 |
+
monetary_decision['log10_org_revenues'] = monetary_decision.org_revenues.apply(np.log10)
|
| 83 |
+
monetary_decision['log10_monetary_sanction'] = monetary_decision.monetary_sanction.apply(np.log10)
|
| 84 |
+
monetary_decision['same_country'] = (monetary_decision.org_country == monetary_decision.authorities_country)
|
| 85 |
+
return monetary_decision
|
stream_app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
-
import numpy as np
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
-
from data_processing import load_data, process_data
|
| 8 |
|
| 9 |
st.title("Data Analysis π π")
|
| 10 |
st.write("by [Teolex](https://www.theolex.io/)")
|
|
@@ -27,29 +26,47 @@ if authority != 'All':
|
|
| 27 |
authority_filter = decisions.authorities_name.apply(lambda a: authority in a)
|
| 28 |
else:
|
| 29 |
authority_filter = decisions.authorities_name.apply(lambda a: bool(set(select_auth) & set(a)))
|
|
|
|
|
|
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
decision_scope = decisions[authority_filter & year_filter]
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
monetary_decision = monetary_decision[monetary_decision.org_revenues != ""]
|
| 40 |
-
monetary_decision['org_revenues'] = monetary_decision.org_revenues.astype(float)
|
| 41 |
-
monetary_decision['log10_org_revenues'] = monetary_decision.org_revenues.apply(np.log10)
|
| 42 |
-
monetary_decision['log10_monetary_sanction'] = monetary_decision.monetary_sanction.apply(np.log10)
|
| 43 |
-
monetary_decision['same_country'] = (monetary_decision.org_country == monetary_decision.authorities_country)
|
| 44 |
fig = px.scatter(monetary_decision,
|
| 45 |
x="org_revenues",
|
| 46 |
y="monetary_sanction",
|
| 47 |
log_x=True,
|
| 48 |
-
log_y=True,
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
hover_name="org_name")
|
| 52 |
st.plotly_chart(fig)
|
| 53 |
-
st.markdown("Comments...")
|
| 54 |
-
st.subheader("1.1 Main takeaways: ")
|
| 55 |
-
st.write("sample text.")
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
import streamlit as st
|
| 3 |
|
|
|
|
| 4 |
import plotly.express as px
|
| 5 |
|
| 6 |
+
from data_processing import load_data, process_data, get_monetary_dataframe
|
| 7 |
|
| 8 |
st.title("Data Analysis π π")
|
| 9 |
st.write("by [Teolex](https://www.theolex.io/)")
|
|
|
|
| 26 |
authority_filter = decisions.authorities_name.apply(lambda a: authority in a)
|
| 27 |
else:
|
| 28 |
authority_filter = decisions.authorities_name.apply(lambda a: bool(set(select_auth) & set(a)))
|
| 29 |
+
year_filter = (decisions.year >= min_year) & (decisions.year <= max_year)
|
| 30 |
+
decision_scope = decisions[authority_filter & year_filter]
|
| 31 |
|
| 32 |
+
# explore monetary sanctions
|
| 33 |
+
monetary_decision = get_monetary_dataframe(decision_scope)
|
| 34 |
|
| 35 |
+
##
|
| 36 |
+
# Plot Graphs
|
| 37 |
+
##
|
| 38 |
+
|
| 39 |
+
st.subheader("The organizations' sectors targeted by the sanctions: ")
|
| 40 |
+
st.markdown("The graph shows the cumulated monetary sanction for the current filters")
|
| 41 |
+
|
| 42 |
+
fig = px.treemap(monetary_decision,
|
| 43 |
+
path=['org_company_type'],
|
| 44 |
+
color='org_revenues',
|
| 45 |
+
color_continuous_scale='RdBu',
|
| 46 |
+
template="simple_white",
|
| 47 |
+
values='monetary_sanction')
|
| 48 |
+
st.plotly_chart(fig)
|
| 49 |
+
|
| 50 |
+
st.subheader("The organizations' regions targeted by the sanctions: ")
|
| 51 |
+
st.markdown("The graph shows the cumulated monetary sanction for the current filters")
|
| 52 |
+
fig = px.treemap(monetary_decision[~monetary_decision.org_continent.isnull()],
|
| 53 |
+
path=['org_continent','org_country'],
|
| 54 |
+
color='org_revenues',
|
| 55 |
+
color_continuous_scale='RdBu',
|
| 56 |
+
template="simple_white",
|
| 57 |
+
values='monetary_sanction')
|
| 58 |
+
st.plotly_chart(fig)
|
| 59 |
|
|
|
|
| 60 |
|
| 61 |
+
st.subheader("Revenues vs monetary sanctions representation ")
|
| 62 |
+
st.markdown("The graph shows the cumulated monetary sanction for the current filters")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
fig = px.scatter(monetary_decision,
|
| 64 |
x="org_revenues",
|
| 65 |
y="monetary_sanction",
|
| 66 |
log_x=True,
|
| 67 |
+
log_y=True,
|
| 68 |
+
template="simple_white",
|
| 69 |
+
color="same_country",
|
| 70 |
+
color_continuous_scale='RdBu',
|
| 71 |
hover_name="org_name")
|
| 72 |
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|