pandas를 사용한 재무 비율 계산

Python으로 재무제표 분석하기

Rohan Chatterjee

Risk Modeler

대차대조표 데이터 구조

  • 대차대조표 데이터가 balance_sheet라는 이름의 pandas DataFrame에 로드되어 있습니다.

 


----CODE_GLUE----
```print(balance_sheet.head())

----CODE_GLUE---- ` 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() 사용

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

연도별 업종별 평균 유동비율이 balance_sheet DataFrame에 추가된 모습을 보여주는 그림.

Python으로 재무제표 분석하기

.groupby().transform() 사용

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

한 기업의 유동비율과 해당 업종의 유동비율 간 상대적 차이를 보여주는 DataFrame.

Python으로 재무제표 분석하기

.isin() 사용

  • .isin()은 분석을 위해 데이터를 부분 집합으로 추출할 때 사용합니다.
  • 예시: 2019년과 2020년의 fmcg와 tech 기업만 포함하도록 DataFrame을 부분 추출:
fmcg_2019 = balance_sheet.loc[
            (balance_sheet["Year"].isin([2019,2020])) &
            (balance_sheet["comp_type"].isin(["tech","fmcg"]))
                            ]
Python으로 재무제표 분석하기

연습해 봅시다!

Python으로 재무제표 분석하기

Preparing Video For Download...