ahmet / Python-for-Data-Science
Herkese Açık Ahmet Kerem Piscine Final
aff_life.py 945 B
import matplotlib.pyplot as plt
from load_csv import load
def main() -> None:
"""Display the life expectancy projection of my campus country."""
country = "Turkey"
dataset = load("../life_expectancy_years.csv")
if dataset is None:
return
if "country" not in dataset.columns:
print("Error: the dataset has no 'country' column")
return
row = dataset[dataset["country"] == country]
if row.empty:
print(f"Error: country not found: {country}")
return
try:
years = row.columns[1:].astype(int)
values = row.iloc[0, 1:].astype(float)
except ValueError:
print("Error: the dataset contains unexpected values")
return
plt.plot(years, values, label=country)
plt.title(f"{country} Life expectancy Projections")
plt.xlabel("Year")
plt.ylabel("Life expectancy")
plt.legend()
plt.show()
if __name__ == "__main__":
main()