Convert numeric column to character in pandas python (integer to string)

Converting numeric column to character in pandas python is carried out using astype() function. Let’s see how to

  •      Typecast or convert numeric column to character in pandas python with an example.

First let’s create a dataframe.


import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
     'Name':['George','Andrea','micheal','maggie','Ravi','Xien','Jalpa'],
   'is_promoted':[0,1,0,0,1,0,1]}

df1 = pd.DataFrame(df1,columns=['Name','is_promoted'])
print(df1)

df1 will be

Convert numeric column to character in pandas 1

Datatypes of df1 will be

Convert numeric column to character in pandas 2

Note: Object datatype of pandas is nothing but character (string) datatype of python

 

Convert numeric column to character in pandas python:

astype() function converts numeric column (is_promoted) to character column as shown below

Convert numeric column to character in pandas 3

“is_promoted” column is converted from numeric(integer)  to character (object).

 

Convert numeric column to character in pandas python (integer to string) prev                                                                                                                Convert numeric column to character in pandas python (integer to string) next