简体   繁体   中英

Converting str to float in pandas warning

I am trying to convert str to float in a pandas data frame and get the following error:

SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

The code:

df_clean['a'] = df_clean['a'].astype(float)

Should I ignore it? Can it be written without generating the warning? Thanks

Maybe try using to_numeric

import pandas as pd
df_clean['a'] = pd.to_numeric(df_clean['a'], errors='ignore')

The "errors" flag gives you different options for how to handle ones that cannot be converted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM