Update app.py
#2
by harshidagli - opened
app.py
CHANGED
|
@@ -37,4 +37,64 @@ world_map = alt.topo_feature(data.world_110m.url, feature='countries')
|
|
| 37 |
|
| 38 |
####### Loading Data #######
|
| 39 |
from iso3166 import countries_by_name
|
| 40 |
-
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
####### Loading Data #######
|
| 39 |
from iso3166 import countries_by_name
|
| 40 |
+
'''
|
| 41 |
+
|
| 42 |
+
import pandas as pd
|
| 43 |
+
import altair as alt
|
| 44 |
+
import ipywidgets as widgets
|
| 45 |
+
from IPython.display import display, clear_output
|
| 46 |
+
|
| 47 |
+
alt.data_transformers.disable_max_rows()
|
| 48 |
+
|
| 49 |
+
url = "contract_awards_in_investment_project_financing_22-11-2024.csv"
|
| 50 |
+
df = pd.read_csv(url)
|
| 51 |
+
|
| 52 |
+
numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns
|
| 53 |
+
|
| 54 |
+
col1_dropdown = widgets.Dropdown(
|
| 55 |
+
options=numeric_columns,
|
| 56 |
+
value=numeric_columns[0],
|
| 57 |
+
description="Column 1:"
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
col2_dropdown = widgets.Dropdown(
|
| 61 |
+
options=numeric_columns,
|
| 62 |
+
value=numeric_columns[1],
|
| 63 |
+
description="Column 2:"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
output = widgets.Output()
|
| 67 |
+
|
| 68 |
+
def update_correlation(change):
|
| 69 |
+
with output:
|
| 70 |
+
clear_output(wait=True)
|
| 71 |
+
|
| 72 |
+
col1 = col1_dropdown.value
|
| 73 |
+
col2 = col2_dropdown.value
|
| 74 |
+
|
| 75 |
+
correlation_value = df[col1].corr(df[col2])
|
| 76 |
+
print(f"Correlation between {col1} and {col2}: {correlation_value:.2f}")
|
| 77 |
+
|
| 78 |
+
# Create a scatter plot
|
| 79 |
+
correlation_plot = (
|
| 80 |
+
alt.Chart(df)
|
| 81 |
+
.mark_circle(size=60)
|
| 82 |
+
.encode(
|
| 83 |
+
x=alt.X(f"{col1}:Q", title=col1),
|
| 84 |
+
y=alt.Y(f"{col2}:Q", title=col2),
|
| 85 |
+
color="Region:N",
|
| 86 |
+
tooltip=["Project Name", "Supplier", col1, col2],
|
| 87 |
+
)
|
| 88 |
+
.properties(
|
| 89 |
+
title=f"Correlation Plot: {col1} vs. {col2}",
|
| 90 |
+
width=600,
|
| 91 |
+
height=400
|
| 92 |
+
)
|
| 93 |
+
)
|
| 94 |
+
display(correlation_plot)
|
| 95 |
+
|
| 96 |
+
col1_dropdown.observe(update_correlation, names='value')
|
| 97 |
+
col2_dropdown.observe(update_correlation, names='value')
|
| 98 |
+
|
| 99 |
+
print("Select columns for correlation analysis:")
|
| 100 |
+
display(col1_dropdown, col2_dropdown, output)
|