Skip to content Skip to sidebar Skip to footer

Pd.to_numeric Converts Entire Series To Nan

I'm trying to convert a column using pd.to_numeric, but for some reason it turns all values (except one) into NaN: In[]: pd.to_numeric(portfolio['Principal Remaining'],errors='coer

Solution 1:

read_csv with thousands=','

df = pd.read_csv('file.csv', thousands=',')

This fixes the problem while reading your data.


replace and to_numeric

df['Principal Remaining'] = pd.to_numeric(
    df['Principal Remaining'].str.replace(',', ''), errors='coerce')

If the first option isn't a choice, you'll need to get rid of the commas first using str.replace, then call pd.to_numeric as shown here.

Post a Comment for "Pd.to_numeric Converts Entire Series To Nan"