File size: 1,565 Bytes
d4fb15e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# -*- coding: utf-8 -*-
"""1084.159.242
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/16y68gc0r9IhP7zQrYaHn726QzpMNc-uz
"""
import pandas as pd
df = pd.read_csv('/content/Cost_of_Living_Index_by_Country_2024.csv')
df.head()
df.describe().T
import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
filtered_world = world[world['name'].isin(df['Country'])]
merged = filtered_world.set_index('name').join(
pd.DataFrame(df).set_index('Country')
)
fig, ax = plt.subplots(1, 1, figsize=(15, 10))
world.boundary.plot(ax=ax)
merged.plot(column='Cost of Living Index', ax=ax, legend=True, legend_kwds={'label': "Cost of Living Index", 'orientation': "horizontal"})
plt.title('Country by Cost of Living Index')
plt.show()
import plotly.express as px
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world.rename(columns={'name': 'Country'})
merged = world.merge(df, on='Country')
fig = px.choropleth(
merged,
locations='Country',
locationmode='country names',
color="Cost of Living Index",
hover_name="Country",
hover_data={
'Cost of Living Index': True,
'Rent Index': True,
'Cost of Living Plus Rent Index': True,
'Groceries Index': True,
'Restaurant Price Index': True,
'Local Purchasing Power Index': True
},
color_continuous_scale=px.colors.sequential.Plasma,
title="Countries by Cost of Living Index"
)
fig.show() |