Financiële overzichten analyseren in Python
Rohan Chatterjee
Risk modeler

pivot_table om gemiddelde ratio’s per bedrijf te berekenen:avg_company_ratio = plot_dat.pivot_table(index=["comp_type",
"company"],
values=["Gross Margin", "Operating Margin",
"Debt-to-equity", "Equity Multiplier"],
aggfunc="mean").reset_index()
print(avg_company_ratio.head())
pivot_table om gemiddelde ratio’s per branche te berekenen:avg_industry_ratio = plot_dat.pivot_table(index="comp_type",
values=["Gross Margin", "Operating Margin",
"Debt-to-equity",
"Equity Multiplier"],
aggfunc="mean").reset_index()
print(avg_industry_ratio.head())
seaborn moet de data in “long” formaat staan. Gebruik pd.melt om avg_industry_ratio en avg_company_ratio te smelten naar long formaat:molten_plot_company = pd.melt(avg_company_ratio, id_vars=["comp_type",
"company"])
molten_plot_industry = pd.melt(avg_industry_ratio,
id_vars=["comp_type"])
print(molten_plot_company.head())
print(molten_plot_industry.head())
pd.concat om molten_plot_company en molten_plot_industry te combinerenmolten_plot_industry heeft geen company-kolom, want het bevat het branchegemiddeldepd.concat vereist dezelfde kolommen; voeg daarom company toe aan molten_plot_industrymolten_plot_industry["company"] = "Industry Average"
molten_plot = pd.concat([molten_plot_company, molten_plot_industry])
sns.barplot(data=molten_plot, y="variable", x="value", hue="company", ci=None)
plt.xlabel(""), plt.ylabel("")
plt.show()

Financiële overzichten analyseren in Python