xxxxxxxxxx
# car_sales is my data, and price is its feature name
# anything that must be replaced is placed in square breackets in repalce
# where square brackets allow us to replace multiple characters
# it will replace thoses characters with empty string
# finally using dtypes, i am changing feature datatype to float
# in my case it is float, u may choose anything u want for example int
car_sales["Price"] = car_sales["Price"].str.replace("[\$\,]","").astype(float)
xxxxxxxxxx
# convert all columns of DataFrame
df = df.apply(pd.to_numeric) # convert all columns of DataFrame
# convert just columns "a" and "b"
df[["a", "b"]] = df[["a", "b"]].apply(pd.to_numeric)
xxxxxxxxxx
# convert Series
my_series = pd.to_numeric(my_series)
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert entire Series
my_series = pd.to_numeric(my_series)
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert Series
my_series = pd.to_numeric(my_series)
#
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert entire Series
my_series = pd.to_numeric(my_series)
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert Series
my_series = pd.to_numeric(my_series)
#
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert entire Series
my_series = pd.to_numeric(my_series)
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
xxxxxxxxxx
# convert entire Series
my_series = pd.to_numeric(my_series)
# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])