String Conversion
Explore how to perform string conversion on data columns using various pandas methods such as apply(), astype(), map(), and applymap(). This lesson helps you standardize data types in your dataset by converting numerical or mixed-type columns to strings, enabling seamless data combination and cleaning.
We'll cover the following...
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 ...