1. Uczyć się
  2. /
  3. Courses
  4. /
  5. Pythonで学ぶ財務諸表分析

Connected

Exercise

ユーザー定義関数で比率を計算する

この演習では、前の演習で作成した関数を使って財務比率を計算します。関数は次のとおりです。

def compute_ratio(df, numerator, denominator, ratio_name, 
                  addition_in_numerator = True,
                  addition_in_denominator = True):
  numerator_of_ratio = np.where(addition_in_numerator,
                             df[numerator].sum(axis=1), 
                             df[numerator[0]] - df[numerator[1:]].sum(
                               axis=1))
  denominator_of_ratio = np.where(addition_in_denominator, 
                               df[denominator].sum(axis=1), 
                               df[denominator[0]] - df[denominator[1:]].sum(axis=1))
  df[ratio_name] = numerator_of_ratio/denominator_of_ratio
  return df

pandas の DataFrame merged_dat が読み込まれています。関数 compute_ratio を使って、このデータを基に財務比率を計算します。

Instrukcje 1 / 2

undefined XP
    1
    2
  • 粗利益率と総資産回転率を計算できるか確認するために、merged_dat の列名を出力してください。