0

I am using pandas to read a csv file and then trying to filter by some condition to remove blank/null/NaN values and then sorting. it still does not filter and returns all the contents. Below is the code. The cells in the csv under the"Status" columns either have some value or they are blank and in some cases have the actual word "NaN."

df = pd.read_csv("**************", encoding="ISO-8859-1")
df = df.loc[(df["Status"] != "Ready") | (df["Status"] != "NaN") | (df["Status"] != "") | (df["Status"] != " ")]
df = df.sort_values(by=["Room Number"])
df = df.reset_index(drop=True)
1
  • 3
    replace "NaN" with np.NaN and import numpy as np Commented Feb 10, 2023 at 16:17

1 Answer 1

0

if u want to remove rows with na, u can use code pd.dropna(axis = 0). for changing " " and any cell for nan befor removing nan, u can use below: df.replace(' ', np.nan, inplace=True)

Sign up to request clarification or add additional context in comments.

1 Comment

if you want to remove rows with na, you can use code pd.dropna(axis = 0). for changing " " and any cell for nan before removing nan, you can use below: df.replace(' ', np.nan, inplace=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.