Subsetting by data types
How can we extract specific data within data using its type? Through subsetting the data with pandas, we can locate and manipulate datasets easily. Subsetting is used frequently during a real analysis as it gives you the power to change data dynamically.
For text data (dtype = object
or dtype = category
), pandas provides methods to perform string transformation that are referred to as "on the fly." These string transforming methods can be accessed through the str
attribute when they're used in a pandas Series or Index.
Let's look at the most important strings methods by covering a few examples:
- We will start by defining a series with a string:
import pandas as pd s = pd.Series(['pandas is awesome']) s
The output will be as follows:
0 pandas is awesome dtype: object