Bắt đầu ngayBắt đầu miễn phí

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 pandasmerged_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.

Bài tập này là một phần của khóa học

Phân tích báo cáo tài chính bằng Python

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# Print the columns of merged_dat
print(merged_dat____)
Chỉnh sửa và Chạy Mã