[Python] How to solve Dataframe to_numeric Error (Python)?

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    I have dataframe that contains float numbers. I want to do numeric operations as sum mult. etc. . Columns types are object. So i have to change this columns into a numeric columns. I use to_numeric function but it gives me NaN as a result.

    How can i solve this problem?

    Code :

    #import libraries
    import pandas as pd

    data = pd.read_csv('file.csv', engine='python', delimiter=';')

    #change object columns into a numeric columnn
    for i in data.columns :
    data = pd.to_numeric(data, errors='coerce')


    Dataframe

    t0 (actual) t0 t0,lower t0,upper
    0 11861,6318726842 0 0 0
    1 4761,43316 5709,1728515625 3776,725188260803 7939,908970830105
    2 36,22841951973635 0 0 0
    3 583,3716479196096 0 0 0
    4 25087,16436661841 26040,7890625 21825,20941707611 31905,394350044822
    ....


    Result :

    t0 (actual) t0 t0,lower t0,upper
    0 NaN NaN NaN NaN
    1 NaN NaN NaN NaN
    2 NaN NaN NaN NaN
    3 NaN NaN NaN NaN
    4 NaN NaN NaN NaN

    Continue reading...

Compartilhe esta Página