Analyzing Financial Statements in Python
Rohan Chatterjee
Risk Modeler
pandas DataFrame called balance_sheet.
print(balance_sheet.head())

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

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

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

.transform() can be used after .groupby() to append the groupby result to rows according to the group each row belongs to.balance_sheet["industry_curr_ratio"] =
balance_sheet.groupby([
"Year","comp_type"])["current_ratio"].transform("mean")
print(balance_sheet.head())

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

.isin() used to subset data for analysis.fmcg and tech companies in the year 2019 and 2020:fmcg_2019 = balance_sheet.loc[
(balance_sheet["Year"].isin([2019,2020])) &
(balance_sheet["comp_type"].isin(["tech","fmcg"]))
]
Analyzing Financial Statements in Python