Manipulating and transforming DataFrames
Before moving on to more advanced recipes, it’s important to understand the fundamentals of working with data. DataFrames are the most common pandas data structures you’ll work with. Despite the existence of hundreds of methods for DataFrame manipulation, only a subset of these are regularly used.
In this recipe, we will show you how to manipulate a DataFrame using the following common methods:
- Creating new columns using aggregates, Booleans, and strings
- Concatenating two DataFrames together
- Pivoting a DataFrame such as Excel
- Grouping data on a key or index and applying an aggregate
- Joining options data together to create straddle prices
Getting ready…
We’ll start by importing the necessary libraries and downloading market price data:
- Start by importing NumPy, pandas, and the OpenBB Platform:
import numpy as np import pandas as pd from openbb import obb obb.user.preferences...