[Python] Drop NaN values from dataframe imported from excel

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to import my data from excel in to python using Pandas. I then want to plot the data. At the moment I am struggling with blank values in my data. Source data looks like attached image. When I run the code as below the data printed contains 'Nan'

    import pandas as pd
    df = pd.read_excel('CSTRS Chem Eng Practicals_2.xlsx', sheet_name='Flow Rates')
    df = pd.DataFrame(df)
    df = df.values
    Time2 = df[4:,0]
    Conc1 = df[4:,2]
    Conc2 = df[4:,4]
    Conc3 = df[4:,6]
    Conc4 = df[4:,8]
    Conc5 = df[4:,10]
    print (Time2)
    print (Conc1)


    If I use df.notna() then I get this error message 'AttributeError: 'numpy.ndarray' object has no attribute 'notna'' Can anyone suggest a way to remove the NaN values so I am able to plot the data

    Thanks

    I have tried df.notna() and I have also tried slicing the data and neither works

    Continue reading...

Compartilhe esta Página