I have written a small code to test how to change datatype of a column of a DataFrame in Python (Version 3.8.5 and running the code in Jupyter Notebook). But it is not changing the datatype. Any idea, what I am doing wrong?
import pandas as pd
data = {'Name':['Tom', 'nick', 'krish', 'jack'],
'Age':['20+', '21.5', '19+', '18.6']}
df = pd.DataFrame(data)
df["Age_Corrected"] = df["Age"].str.replace("+","")
df
df["Age_Corrected"].astype("float")
df.info()
But I am not getting Age_Corrected as float. It is still showing object. The result I am getting from df.info() is given below.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Name 4 non-null object
1 Age 4 non-null object
2 Age_Corrected 4 non-null object
dtypes: object(3)
memory usage: 112.0+ bytes