Aan de slagGa gratis aan de slag

Making a facet grid plot

In the previous exercise, you wrote the following code:

# Subset tech and fmcg companies
subset_dat = dataset.loc[dataset["comp_type"].isin(["tech", "fmcg"])]

# Compute yearly average gross margin ratio of tech and fmcg companies
subset_dat_avg = subset_dat.pivot_table(index=["Year", "comp_type"], values = "gross_margin").reset_index()

#Add column company
subset_dat_avg["company"] = np.where(subset_dat_avg["comp_type"]=="tech", "Avg tech", "Avg fmcg")

#Concat the DataFrames
plot_df = pd.concat([subset_dat, subset_dat_avg], axis=0)

The code prepared the data to make the following plot: This plot shows the gross margin of tech companies, FMCG companies, the average tech company, and the average FMCG companies over many years.

Now it's time to make the plot.

Deze oefening maakt deel uit van de cursus

Analyzing Financial Statements in Python

Cursus bekijken

Oefeninstructies

  • Use the DataFrame plot_df to make the facet grid plot in the description using seaborn.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Make the plot
sns.relplot(data=plot_df.reset_index(drop=True), ____)
plt.show()
plt.close()
Code bewerken en uitvoeren