Home  >  Q&A  >  body text

python - How to delete a row in a dataframe when a column value is nan?


When the value of just my luck is nan, delete the two lines of Jack Matthews and Micheal Phillips

为情所困为情所困2711 days ago1232

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 11:04:08

    Two methods:
    1. Delete the line where just my luck is NaN

        indexs = list(df[np.isnan(df['just my luck'])].index)
        df = df.drop(indexs)

    2. Get the row where just my luck is not NaN

        df = df[np.isnan(df['just my luck']) == False]

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-18 11:04:08

    df = df.dropna(subset=["just my luck"])

    reply
    0
  • Cancelreply