String Conversion
Learn how to apply a string data type to a column.
Method 1: Using apply()
Whenever we want to combine a numerical column that contains an integer
data type with another column containing a string
data type, we perform string conversion. For example, suppose a DataFrame contains the columns, house_no
, estate
, and town
, with integer
, string
, and string
data types, respectively. In that case, we can convert house_no
from an integer
data type to a string
data type to combine it with the other columns and create a new address
column. If we attempted to combine columns with string
and integer
types, we would get an error.
Let's run the code below to perform string conversion.
Note: We don't check the column data types because we're familiar with the dataset.
Get hands-on with 1400+ tech skills courses.