| |
|
|
| |
|
|
|
|
| import streamlit as st |
| import altair as alt |
| import pandas as pd |
| import pycountry |
| from vega_datasets import data |
| |
| st.write('Group 14 - Harshi, Sharanya & Jeenal') |
| |
| st.title('World Bank Contracts Analysis') |
|
|
| st.write('This dashboard provides an in-depth analysis of how these contracts are distributed across countries, their trends over time and potential correlations between key metrics. Dive in to uncover meaningful patterns that reflect the impact of these investments globally.') |
|
|
| |
| st.write('This analysis uses data from **World Bank Contract Awards**, detailing information about contracts under Investment Project Financing (IPF). It includes attributes such as country, fiscal year, contract numbers and more. By examining these attributes, we aim to highlight the distribution, trends and interdependencies in the global investment landscape.') |
|
|
| st.write("**Key Attributes of the Dataset:**") |
| st.write(""" |
| - **Borrower Country / Economy**: The country or economy receiving the contract. |
| - **Fiscal Year**: The year the contract was signed, allowing for trend analysis. |
| - **WB Contract Number**: Unique identifier for each contract. |
| - **Contract Amount**: The financial value of the contract. |
| - **Procurement Method**: The method used for awarding the contract. |
| """) |
|
|
| st.write('Dataset is 99 MB, large enough for us to upload it on GitHub.') |
| |
| url = "contract_awards_in_investment_project_financing_22-11-2024.csv" |
| df = pd.read_csv(url, parse_dates=['As of Date', 'Fiscal Year', 'Contract Signing Date'], date_format={'As of Date': '%Y-%m-%d', 'Contract Signing Date': '%Y-%m-%d'}) |
| df['Fiscal Year'] = df['Fiscal Year'].dt.year |
| |
|
|
| df['Fiscal Year'] = df['Fiscal Year'].astype(int) |
|
|
| |
| chart_data = df.groupby(['Borrower Country / Economy', 'Fiscal Year'])['WB Contract Number'].count() |
| |
|
|
| |
|
|
| @st.cache_data |
| def get_country_data(): |
| |
| country_data = [] |
| for country in pycountry.countries: |
| try: |
| country_data.append({ |
| 'id': int(country.numeric), |
| 'name': country.name |
| }) |
| except: |
| continue |
| return pd.DataFrame(country_data) |
|
|
| countries = alt.topo_feature(data.world_110m.url, 'countries') |
| country_df = get_country_data() |
| |
|
|
| |
| selection = alt.selection_single(fields=['name'], empty='none') |
|
|
| |
| map_chart = alt.Chart(countries).mark_geoshape( |
| stroke='white' |
| ).transform_lookup( |
| lookup='id', |
| from_=alt.LookupData(country_df, 'id', ['name']) |
| ).transform_filter( |
| alt.FieldOneOfPredicate(field='name', oneOf=list(df['Borrower Country / Economy'].unique())) |
| ).encode( |
| tooltip='name:N', |
| color=alt.condition( |
| selection, |
| alt.value('green'), |
| alt.value('lightgray')), |
| ).properties( |
| width=900, |
| height=400 |
| ).project('naturalEarth1').add_selection(selection) |
|
|
|
|
| |
| merged_data = pd.merge(chart_data.reset_index(), country_df, left_on='Borrower Country / Economy', right_on='name', how='left') |
| |
|
|
| st.header('Trend of contracts acquired by country in the past years') |
|
|
| st.write('This interactive map highlights the countries that have received World Bank contracts. By hovering over a country, you can explore its name and status. This visualization provides an overview of global contract distribution, emphasizing regions with significant activity.') |
|
|
| |
| st.write("Hover over a country to see its contract data over time") |
|
|
| if selection != 'none': |
| line_plot = alt.Chart(merged_data).mark_line().encode( |
| x=alt.X('Fiscal Year:N', axis=alt.Axis(title='Fiscal Year')), |
| y=alt.Y('WB Contract Number:Q', axis=alt.Axis(title='Total Contracts')), |
| |
| tooltip=['Fiscal Year', 'WB Contract Number'] |
| ).transform_filter( |
| selection |
| ).properties( |
| title=f'Total Contracts per Fiscal Year', |
| width=400, |
| height=300 |
| ) |
| final_chart = map_chart & line_plot |
|
|
| st.altair_chart(final_chart, use_container_width=True) |
| else: |
| st.altair_chart(map_chart, use_container_width=True) |
| st.write('Choose a country to learn more about contract trends') |
| |
|
|
|
|
| |
| numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns |
| st.header("Correlation Analysis") |
| st.write('This section allows you to investigate the relationships between numeric attributes in the dataset. For example, examining correlations between **Contract Amount** and **Procurement Method Frequency** can provide insights into procurement practices and financial strategies.') |
|
|
| col1 = st.selectbox("Select First Numeric Attribute", numeric_columns, index=0) |
| col2 = st.selectbox("Select Second Numeric Attribute", numeric_columns, index=1) |
|
|
| correlation_value = df[col1].corr(df[col2]) |
| st.write(f"**Correlation between {col1} and {col2}: {correlation_value:.2f}**") |
|
|
| correlation_plot = ( |
| alt.Chart(df) |
| .mark_circle(size=60) |
| .encode( |
| x=alt.X(f"{col1}:Q", title=col1, scale=alt.Scale(zero=False)), |
| y=alt.Y(f"{col2}:Q", title=col2, scale=alt.Scale(zero=False)), |
| color="Region:N", |
| tooltip=["Project Name", "Supplier", col1, col2], |
| ) |
| .properties( |
| title=f"Correlation Plot: {col1} vs. {col2}", |
| width=600, |
| height=400 |
| ) |
| ) |
| st.altair_chart(correlation_plot, use_container_width=True) |
|
|
| |
| st.write('The correlation plot allows experts to explore relationships between different numeric variables in the dataset. For instance, examining the correlation between Contract Amount and Procurement Method Frequency can reveal patterns in procurement practices. A strong correlation might indicate certain procurement methods are associated with higher or lower contract values, providing insights into efficiency and strategy. Users can select specific attributes to analyze and dynamically visualize how they interact across regions and industries.') |
|
|
| |
| st.header('Contextualization') |
| st.write('Contextual Dataset') |
| st.write('World Bank Development Indicators by Industry') |
| st.write('Link: https://databank.worldbank.org/source/world-development-indicators') |
| st.write('Why Useful: This dataset includes industry-specific GDP contributions and growth metrics for different countries. Integrating it with contract award data can help analyze whether investments align with industry needs or economic potential, enabling an evaluation of their effectiveness.') |
| st.write('Additional Insight') |
| st.write('The correlation analysis combined with the contextual dataset could provide narratives such as:') |
| st.write('How contract investments influence specific industries.') |
| st.write('Patterns in procurement methods tied to economic growth in particular regions or industries.') |
|
|