Replace empty rows pandas

I have some empty rows in Bidfloor df_g column so I want to change they with floorprice

the problem is if I do this: df_g.loc[df_g['Bidfloor'] == 0, 'Bidfloor'] = floorprice the funtion works but I don't have 0 in the rows, so I'm tring with: df_g.loc[df_g['Bidfloor'] == '', 'Bidfloor'] = floorprice to simulate the empty row but I have this error: TypeError: invalid type comparison

floorprice = 0.2
df_g.loc[df_g['Bidfloor'] == '', 'Bidfloor'] = floorprice

1 answer

  • answered 2018-03-20 19:43 pault

    The problem is that you are checking to see if your value is an empty string, where you should be checking to see if it's null.

    This will give you the desired output:

    import pandas as pd
    floorprice = 0.2
    df_g.loc[pd.isnull(df_g['Bidfloor']) == True, 'Bidfloor'] = floorprice

    pandas.isnull() will return True if the value is missing.