harshidagli commited on
Commit
0fa4ba3
·
verified ·
1 Parent(s): be71e63

Correlation Plot

Browse files
Files changed (1) hide show
  1. app.py +58 -1
app.py CHANGED
@@ -37,4 +37,61 @@ 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 ipywidgets as widgets
43
+ from IPython.display import display, clear_output
44
+
45
+ alt.data_transformers.disable_max_rows()
46
+
47
+ url = "contract_awards_in_investment_project_financing_22-11-2024.csv"
48
+ df = pd.read_csv(url)
49
+
50
+ numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns
51
+
52
+ col1_dropdown = widgets.Dropdown(
53
+ options=numeric_columns,
54
+ value=numeric_columns[0],
55
+ description="Column 1:"
56
+ )
57
+
58
+ col2_dropdown = widgets.Dropdown(
59
+ options=numeric_columns,
60
+ value=numeric_columns[1],
61
+ description="Column 2:"
62
+ )
63
+
64
+ output = widgets.Output()
65
+
66
+ def update_correlation(change):
67
+ with output:
68
+ clear_output(wait=True)
69
+
70
+ col1 = col1_dropdown.value
71
+ col2 = col2_dropdown.value
72
+
73
+ correlation_value = df[col1].corr(df[col2])
74
+ print(f"Correlation between {col1} and {col2}: {correlation_value:.2f}")
75
+
76
+ correlation_plot = (
77
+ alt.Chart(df)
78
+ .mark_circle(size=60)
79
+ .encode(
80
+ x=alt.X(f"{col1}:Q", title=col1),
81
+ y=alt.Y(f"{col2}:Q", title=col2),
82
+ color="Region:N",
83
+ tooltip=["Project Name", "Supplier", col1, col2],
84
+ )
85
+ .properties(
86
+ title=f"Correlation Plot: {col1} vs. {col2}",
87
+ width=600,
88
+ height=400
89
+ )
90
+ )
91
+ display(correlation_plot)
92
+
93
+ col1_dropdown.observe(update_correlation, names='value')
94
+ col2_dropdown.observe(update_correlation, names='value')
95
+
96
+ print("Select columns for correlation analysis:")
97
+ display(col1_dropdown, col2_dropdown, output)