Блог им. Albus
# -*- coding: utf-8 -*- import pandas as pd import matplotlib.pyplot as plt url = 'http://cbr.ru/vfs/statistics/credit_statistics/debt/debt_sustainability.xlsx' df = pd.read_excel (url, skiprows = 3) build_charts = {1: ('Внешний долг РФ к ВВП', '%'), 6: ('Внешний долг РФ на душу населения', '$')} df.columns = [i for i in range(len(df.columns))] df = df.dropna() df = df[df[3] != '-'] df_last_row = pd.DataFrame() if len(df.iloc[-1, 0]) > 4: df_last_row = df.iloc[[-1]] df = df[df[0].apply(lambda x: str(x).isdigit())] df = df.append(df_last_row) df[0] = df[0].astype('str') print(df.to_string()) plt.rcParams.update({'font.size': 16}) for key in build_charts: print('Строю график ' + build_charts[key][0]) fig, ax = plt.subplots(1, 1, figsize=(15, 10)) ax.margins(x=0) ax.plot(df[0], df[key], color="g", linewidth=3) plt.xticks(rotation=33) plt.title(build_charts[key][0] + ', ' + build_charts[key][1], fontsize = 30) plt.grid() plt.text(df[0].iloc[-1], df[key].iloc[-1], str(round (df[key].iloc[-1], 2)) + build_charts[key][1]) plt.savefig(build_charts[key][0] + '.png', dpi=150, format='png')