Reorganizing and reshaping data
When working with financial information, it is often the case that data retrieved from almost any data source will not be in the format that you need to perform the analyses that you want.
Or perhaps, just as likely, the data from a specific source may be incomplete and require collection of data from another source, at which point, the data needs to be either concatenated or merged through join-like operations across the data.
Even if the data is complete or after combining it from various sources, it may still be organized in a manner that is not conducive to a specific type of analysis. Hence, it needs to be restructured.
Fortunately, pandas provides rich capabilities for concatenating, merging, and pivoting data. These following sections take us through several common scenarios of each, using stock data.
Concatenating multiple DataFrame objects
Concatenation in pandas is the process of creating a new pandas object by combining data from two (or more pandas...