pandas로 재무 비율 계산하기

Python으로 재무제표 분석하기

Rohan Chatterjee

Risk Modeler

대차대조표 데이터 구조

  • 대차대조표 데이터는 pandas DataFrame balance_sheet에 로드되었습니다.

 

print(balance_sheet.head()) balance_sheet DataFrame 상단을 보여주는 이미지.

Python으로 재무제표 분석하기

유동비율 계산하기

balance_sheet["current_ratio"] = balance_sheet["Total Current Assets"] / 
                                 balance_sheet["Total Current Liabilities"]
print(balance_sheet.head())

current_ratio 열이 추가된 balance_sheet DataFrame.

Python으로 재무제표 분석하기

.groupby()로 그룹별 결과 구하기

  • 업계별 평균 유동비율 구하기:
    balance_sheet.groupby("comp_type")["current_ratio"].mean()
    
    업계별 평균 유동비율을 보여주는 이미지.
Python으로 재무제표 분석하기

.groupby()로 그룹별 결과 구하기

balance_sheet.groupby(["Year","comp_type"])["current_ratio"].mean()

연도별 업계 평균 유동비율을 보여주는 이미지.

Python으로 재무제표 분석하기

groupby().transform() 사용하기

  • .groupby().transform()을 사용하면 각 행이 속한 그룹의 결과를 행에 추가할 수 있습니다.
    balance_sheet["industry_curr_ratio"] = 
              balance_sheet.groupby([
              "Year","comp_type"])["current_ratio"].transform("mean")
    print(balance_sheet.head())
    

연도·업계별 평균 유동비율이 balance_sheet에 추가된 모습.

Python으로 재무제표 분석하기

.groupby().transform() 사용하기

balance_sheet["relative_diff"] = 
                            (balance_sheet["current_ratio"] / 
                             balance_sheet["industry_curr_ratio"]) - 1

기업의 유동비율과 업계 유동비율 간 상대 차이를 보여주는 DataFrame.

Python으로 재무제표 분석하기

.isin() 사용하기

  • .isin()은 분석을 위한 하위 집합을 선택할 때 사용합니다.
  • 예: 2019·2020년의 fmcgtech 기업만 필터링:
fmcg_2019 = balance_sheet.loc[
            (balance_sheet["Year"].isin([2019,2020])) &
            (balance_sheet["comp_type"].isin(["tech","fmcg"]))
                            ]
Python으로 재무제표 분석하기

Ayo berlatih!

Python으로 재무제표 분석하기

Preparing Video For Download...