convert dataframe to float

38

convert dataframe to float -

df["data"] = df["data"].astype(float)

convert column to numeric pandas -

# 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)

convert dataframe column to float -

df["col"] = df["col"].astype(float)

pandas dataframe convert string to float -

df_raw['PricePerSeat_Outdoor'] = pd.to_numeric(df_raw['PricePerSeat_Outdoor'], errors='coerce')

convert price to float pandas -

df[df.columns[1:]] = df[df.columns[1:]].replace('[\$,]', '', regex=True).astype(float)

Comments

Submit
0 Comments