Skip to content

Commit b68b064

Browse files
committed
update code length
1 parent 105d900 commit b68b064

File tree

1 file changed

+21
-52
lines changed

1 file changed

+21
-52
lines changed

lectures/inflation_history.md

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ def process_df(df):
231231
"Clean and reorganize the entire dataframe."
232232
233233
# remove HTML markers from column names
234-
for item in ['<s>a</s>', '<s>c</s>',
235-
'<s>d</s>', '<s>e</s>']:
234+
for item in ['<s>a</s>', '<s>c</s>', '<s>d</s>', '<s>e</s>']:
236235
df.columns = df.columns.str.replace(item, '')
237236
238237
# convert years to int
@@ -266,18 +265,12 @@ def pe_plot(p_seq, e_seq, index, labs, ax):
266265
p_lab, e_lab = labs
267266
268267
# plot price and exchange rates
269-
ax.plot(index, p_seq,
270-
label=p_lab,
271-
color='tab:blue')
268+
ax.plot(index, p_seq, label=p_lab, color='tab:blue')
272269
273270
# add a new axis
274271
ax1 = ax.twinx()
275-
ax1.plot([None], [None],
276-
label=p_lab,
277-
color='tab:blue')
278-
ax1.plot(index, e_seq,
279-
label=e_lab,
280-
color='tab:orange')
272+
ax1.plot([None], [None], label=p_lab, color='tab:blue')
273+
ax1.plot(index, e_seq, label=e_lab, color='tab:orange')
281274
282275
# set log axes
283276
ax.set_yscale('log')
@@ -292,20 +285,16 @@ def pe_plot(p_seq, e_seq, index, labs, ax):
292285
label.set_rotation(45)
293286
294287
# set labels
295-
ax.text(-0.08, 1.03,
296-
'Price Level',
297-
transform=ax.transAxes)
298-
ax.text(0.92, 1.03,
299-
'Exchange Rate',
300-
transform=ax.transAxes)
288+
ax.text(-0.08, 1.03, 'Price Level', transform=ax.transAxes)
289+
ax.text(0.92, 1.03, 'Exchange Rate', transform=ax.transAxes)
301290
302291
ax1.legend(loc='upper left')
303292
304293
return ax1
305294
306295
def pr_plot(p_seq, index, ax):
307296
"Generate plots for inflation rates."
308-
297+
309298
# alculate the difference of log p_seq
310299
log_diff_p = np.diff(np.log(p_seq))
311300
@@ -315,11 +304,8 @@ def pr_plot(p_seq, index, ax):
315304
color='tab:grey')
316305
317306
# calculate and plot moving average
318-
diff_smooth = pd.DataFrame(
319-
log_diff_p).rolling(3).mean()
320-
ax.plot(index[1:], diff_smooth,
321-
alpha=0.5,
322-
color='tab:grey')
307+
diff_smooth = pd.DataFrame(log_diff_p).rolling(3).mean()
308+
ax.plot(index[1:], diff_smooth, alpha=0.5, color='tab:grey')
323309
ax.text(-0.08, 1.03,
324310
'Monthly Inflation Rate',
325311
transform=ax.transAxes)
@@ -363,10 +349,8 @@ for i in range(4):
363349
364350
# apply process_entry on the selected sheet
365351
sheet_list = [
366-
pd.read_excel(
367-
xls,
368-
'Table3.' + str(ind),
369-
header=1).iloc[:row].applymap(process_entry)
352+
pd.read_excel(xls, 'Table3.' + str(ind),
353+
header=1).iloc[:row].applymap(process_entry)
370354
for ind, row in zip(indices, rows)]
371355
372356
sheet_list = [process_df(df) for df in sheet_list]
@@ -398,18 +382,14 @@ The sources of our data are:
398382
* Table 3.4, exchange rate with US
399383

400384
```{code-cell} ipython3
401-
p_seq = df_Aus['Retail price index,'
402-
' 52 commodities']
385+
p_seq = df_Aus['Retail price index, 52 commodities']
403386
e_seq = df_Aus['Exchange Rate']
404387
405-
lab = ['Retail Price Index',
406-
'Exchange Rate']
388+
lab = ['Retail Price Index', 'Exchange Rate']
407389
408390
# create plot
409391
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
410-
_ = pe_plot(p_seq, e_seq,
411-
df_Aus.index,
412-
lab, ax)
392+
_ = pe_plot(p_seq, e_seq, df_Aus.index, lab, ax)
413393
414394
# connect disjunct parts
415395
plt.figtext(0.5, -0.02, 'Austria',
@@ -453,9 +433,7 @@ lab = ['Hungarian Index of Prices',
453433
454434
# create plot
455435
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
456-
_ = pe_plot(p_seq, e_seq,
457-
df_Hung.index,
458-
lab, ax)
436+
_ = pe_plot(p_seq, e_seq, df_Hung.index, lab, ax)
459437
460438
plt.figtext(0.5, -0.02, 'Hungary',
461439
horizontalalignment='center',
@@ -499,10 +477,8 @@ p_seq3 = df_Pol['Wholesale Price Index: '
499477
mask_1 = p_seq1[~p_seq1.isna()].index[-1]
500478
mask_2 = p_seq2[~p_seq2.isna()].index[-2]
501479
502-
adj_ratio12 = (p_seq1[mask_1]
503-
/ p_seq2[mask_1])
504-
adj_ratio23 = (p_seq2[mask_2]
505-
/ p_seq3[mask_2])
480+
adj_ratio12 = (p_seq1[mask_1] / p_seq2[mask_1])
481+
adj_ratio23 = (p_seq2[mask_2] / p_seq3[mask_2])
506482
507483
# glue three series
508484
p_seq = pd.concat([p_seq1[:mask_1],
@@ -511,8 +487,7 @@ p_seq = pd.concat([p_seq1[:mask_1],
511487
p_seq = p_seq[~p_seq.index.duplicated(keep='first')]
512488
513489
# exchange rate
514-
e_seq = 1/df_Pol['Cents per Polish mark '
515-
'(zloty after May 1924)']
490+
e_seq = 1/df_Pol['Cents per Polish mark (zloty after May 1924)']
516491
e_seq[e_seq.index > '05-01-1924'] = np.nan
517492
```
518493

@@ -522,9 +497,7 @@ lab = ['Wholesale Price Index',
522497
523498
# create plot
524499
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
525-
ax1 = pe_plot(p_seq, e_seq,
526-
df_Pol.index,
527-
lab, ax)
500+
ax1 = pe_plot(p_seq, e_seq, df_Pol.index, lab, ax)
528501
529502
plt.figtext(0.5, -0.02, 'Poland',
530503
horizontalalignment='center',
@@ -560,9 +533,7 @@ lab = ['Price Index',
560533
561534
# create plot
562535
fig, ax = plt.subplots(figsize=[9,5], dpi=200)
563-
ax1 = pe_plot(p_seq, e_seq,
564-
df_Germ.index,
565-
lab, ax)
536+
ax1 = pe_plot(p_seq, e_seq, df_Germ.index, lab, ax)
566537
567538
plt.figtext(0.5, -0.06, 'Germany',
568539
horizontalalignment='center',
@@ -586,9 +557,7 @@ lab = ['Price Index (Marks or converted to Marks)',
586557
587558
# create plot
588559
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
589-
ax1 = pe_plot(p_seq, e_seq,
590-
df_Germ.index,
591-
lab, ax)
560+
ax1 = pe_plot(p_seq, e_seq, df_Germ.index, lab, ax)
592561
593562
plt.figtext(0.5, -0.02, 'Germany',
594563
horizontalalignment='center',

0 commit comments

Comments
 (0)