Reshaping data
Data isn't always given to us in the format that's most convenient for our analysis. Therefore, we need to be able to restructure data into both wide and long formats, depending on the analysis we want to perform. For many analyses, we will want wide format data so that we can look at the summary statistics easily and share our results in that format.
However, this isn't always as black and white as going from long format to wide format or vice versa. Consider the following data from the Exercises section:
It's possible to have data where some of the columns are in wide format (open, high, low, close, volume), but others are in long format (ticker). Summary statistics using describe()
on this data aren't helpful unless we first filter on ticker. This format makes it easy to compare the stocks; however, as we briefly discussed when we learned about...