1. Lära sig
  2. /
  3. Courses
  4. /
  5. Phân tích báo cáo tài chính bằng Python

Connected

exercise

Tính các tỷ số bằng hàm do bạn định nghĩa

Trong bài tập này, bạn sẽ dùng hàm từ bài trước để tính các tỷ số tài chính. Nhắc lại rằng hàm là:

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

Đối tượng DataFrame của pandas là merged_dat đã được nạp sẵn cho bạn. Bạn sẽ dùng nó để tính các tỷ số tài chính bằng hàm compute_ratio.

Instruktioner 1 / 2

undefined XP
    1
    2
  • In ra các cột của merged_dat để kiểm tra xem bạn có thể tính biên lợi nhuận gộp và hệ số vòng quay tài sản hay không.