Repository navigation
Description
Dear John @jstac and Matt @mmcky ,
After reviewing the lecture long_run_growth.ipynb (related to #350 ), I don't see any deprecated or significantly changed functionality that would require updates related to pandas >=2.0. The code appears to be compatible with recent pandas versions.
In the last block of code in section Early industrialization:
fig, ax = plt.subplots(dpi=300)
country = ['DEU', 'USA', 'SUN', 'BEM', 'FRA', 'JPN']
start_year, end_year = (1821, 1945)
draw_interp_plots(gdp[country].loc[start_year:end_year],
country,
'international dollars', 'year',
color_mapping, code_to_name, 2, False, ax)
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300,
bbox_inches='tight')
plt.show()I believe the plt.savefig part may not be necessary. When I run this code in my Jupyter Notebook, it generates an error. Removing this part should still allow the plot to be generated successfully.
Do you think we should change this code?
Here are the details for reviewing the pandas-related code in this lecture.
- Reading Excel files:
data = pd.read_excel(data_url, sheet_name='Full data')This is still valid in recent pandas versions.
- DataFrame:
data.set_index(['countrycode', 'year'], inplace=True)
data['gdp'] = data['gdppc'] * data['pop']
gdp = data['gdp'].unstack('countrycode')These operations are still valid.
- DataFrame:
code_to_name = data[['countrycode', 'country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])This is still valid.
- Interpolation:
gdp_pc[country].interpolate()This method is still supported.
- Plotting:
gdp_pc[country].plot(ax=ax, ylabel='international dollars', xlabel='year', color=color_mapping[country])This plotting method is still valid.
- Columns
data.columns = data.columns.droplevel(level=2)This is still supported.
- DateTime conversion:
regionalgdp_pc.index = pd.to_datetime(regionalgdp_pc.index, format='%Y')This is still valid.
Best ❤️
Longye
Activity
mmcky commentedon Jun 21, 2024
thanks @longye-tian. Very nice review.
This is saving the figure that we use at the beginning of the lecture using a
figuredirective. You're right -- it may not be necessary but perhaps we should copy of the code that is used to generate that figure and add it to_static/lecture_specific/long_run_growthin afigures.ipynbnotebook.mmcky commentedon Jul 1, 2024
thanks again @longye-tian for reviewing the pandas code. Appreciate the review. This issue can now be closed.