#!/usr/bin/env python # coding: utf-8 # API? # In[31]: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt #allow to see all rows pd.set_option('display.max_rows', None) # Assuming you have loaded the CSV data and named it 'spei2' # Replace 'path_to_your_downloaded_file.csv' with the actual path spei2 = pd.read_csv('C:/Users/jtrum/world_bank/data/luandaSPEI.csv', delimiter=';') spei2.columns = ['year', 'spei'] spei2.columns = ['year', 'spei'] # Convert 'year' column to datetime spei2['year'] = pd.to_datetime(spei2['year']) # Add a new column for line color based on SPEI values spei2['line_color'] = ['positive' if spei > 0 else 'negative' for spei in spei2['spei']] # Create the line chart using Seaborn with connected lines plt.figure(figsize=(10, 6)) sns.lineplot(data=spei2, x='year', y='spei', hue='line_color', linewidth=2) # Add labels and title plt.xlabel('Year') plt.ylabel('SPEI') plt.title('SPEI Over Time with Colored Lines') plt.xticks(rotation=45) plt.grid(True) plt.show() # In[1]: # In[33]: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt #load data spei = pd.read_csv("C:/Users/jtrum/world_bank/data/luandaSPEI.csv", delimiter=";") spei.columns = ["date", "spei"] #get the year from each date spei["year"] = spei["date"].str[:4] #group by year and get the mean spei spei2 = spei.groupby("year").mean() spei2 # In[37]: from matplotlib.ticker import MultipleLocator #plot the data as a line chart plt.figure(figsize=(10, 6)) sns.lineplot(data=spei2, color='#1E2F97', x="year", y="spei", linewidth=1) plt.xlabel("Year") plt.ylabel("SPEI") x_locator = MultipleLocator(base=10) plt.gca().xaxis.set_major_locator(x_locator) plt.axhline(y=0, color='red', linestyle='--', linewidth=0.5) plt.title("Standardized Precipiatation-Evapotranspiration Index (SPEI) - Luanda, Angola") plt.xticks(rotation=45) plt.grid(True) plt.show()