Exercise

Plotting ratios in one figure

In this exercise, you'll plot and compute the gross margin and asset turnover ratio of Microsoft over time. But unlike the last exercise, here you will plot it in one figure. This will help visually analyze the trend of these ratios since the ratios are plotted in the same figure.

You will use the pandas .melt() function in this exercise. In the video, the value_vars argument was specified in the function. value_vars refer to the columns we want to unpivot. However if value_vars is not specified, then all the columns which are not id_vars will be taken as value_vars.

Asset turnover and gross margin ratios have been computed for you in the msft DataFrame, provided in the "asset_turnover" and "gross_margin" columns, respectively.

Instructions

100 XP
  • Convert the msft DataFrame from wide to long format.
  • Plot the asset turnover ratio and gross margin ratio in the same plot with Year on the x-axis and add hue over the dimension of Ratio.