Search code examples
pandasdataframemissing-data

Unable to drop rows with missing (0) value -Dataframe


I tried to drop the row with missing values (0) in them but it didn't work. When I extracted to an excel file, it is still showing a lot of rows with 0 value in my variable GTCBSA. Did I write my drop function incorrectly?

for i in range(2004,2007):
   url = f"https://api.census.gov/data/{i}/cps/basic/jun?get=GTCBSA,PEFNTVTY"
   a = pd.read_json(url)
   a = pd.DataFrame(a.iloc[1:,]).set_axis(a.iloc[0,], axis="columns", inplace=False)
   a.dropna(subset = ["GTCBSA"])

a
   

enter image description here


Solution

  • What you are using would only give you results if the values are actually missing like being (Nan). Not if the value is 0.

    Based on the answers above checking that the value is equal to zero also is not working for you. The only thing I can think of is that the values are maybe strings.

    I think you should try something like this:

    df = df[~(df['GTCBSA'] == '0')]