@@ -30,7 +30,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie
3030``` {code-cell} ipython3
3131:tags: [hide-output]
3232
33- !pip install --upgrade polars wbgapi yfinance
33+ !pip install --upgrade polars wbgapi yfinance pyarrow
3434```
3535
3636## Overview
@@ -774,7 +774,7 @@ price_change_df = ticker.select([
774774
775775# Add company names and sort
776776price_change_df = price_change_df.with_columns([
777- pl.col('ticker').replace (ticker_list, default=pl.col('ticker')).alias('company')
777+ pl.col('ticker').replace_strict (ticker_list, default=pl.col('ticker')).alias('company')
778778]).sort('pct_change')
779779
780780print(price_change_df)
@@ -874,6 +874,13 @@ Generate summary statistics using Polars:
874874summary_stats = yearly_returns.select(list(indices_list.values())).describe()
875875print("Summary Statistics:")
876876print(summary_stats)
877+
878+ # Check for any null values or data issues
879+ print(f"\nData shape: {yearly_returns.shape}")
880+ print(f"Null counts:")
881+ print(yearly_returns.null_count())
882+ print(f"\nData range (first few years):")
883+ print(yearly_returns.head())
877884```
878885
879886Plot the time series:
@@ -891,12 +898,15 @@ for iter_, ax in enumerate(axes.flatten()):
891898 # Get index name per iteration
892899 index_name = list(indices_list.values())[iter_]
893900
894- # Plot pct change of yearly returns per index
895- ax.plot(df_pandas.index, df_pandas[index_name])
896- ax.set_ylabel("percent change ", fontsize=12)
901+ # Plot with markers and lines for better visibility
902+ ax.plot(df_pandas.index, df_pandas[index_name], 'o-', linewidth=2, markersize=4 )
903+ ax.set_ylabel("yearly return ", fontsize=12)
897904 ax.set_xlabel("year", fontsize=12)
898- ax.set_title(index_name)
905+ ax.set_title(index_name, fontsize=12 )
899906 ax.grid(True, alpha=0.3)
907+
908+ # Add horizontal line at zero for reference
909+ ax.axhline(y=0, color='k', linestyle='--', alpha=0.3)
900910
901911plt.tight_layout()
902912plt.show()
0 commit comments