0

The code seems to run without issue but when I run .describe the values are still there. What am I doing wrong? I am trying to delete -999 values in my dataframe for all the columns with :

cols=['#objid','u','g','r','i','z','redshift']
for col in cols:
    data_mag_clean=data_mag.drop(data_mag[data_mag[col] < 0].index)

as I said the code runs without errors but nothing gets deleted.

  • Drop in place: `.drop(data_mag[data_mag[col] < 0].index, inplace=True)` – Psidom Jun 18 '21 at 17:35
  • kindly post a snapshot of dataframe with the values. – Amit Gupta Jun 18 '21 at 17:36
  • 1
    Does this answer your question? [Deleting DataFrame row in Pandas based on column value](https://stackoverflow.com/questions/18172851/deleting-dataframe-row-in-pandas-based-on-column-value) – Amit Gupta Jun 18 '21 at 17:46

2 Answers2

0

If I understand it well, you're trying to delete rows from the dataframe which has -999 value. If this is the case then this should work

for col in cols:
    data_mag_clean = data_mag[data_mag.col != -999]
Amit Gupta
  • 2,698
  • 4
  • 24
  • 37
0

Found the problem!!! it was the for loop and setting data_mag_clean = data_mag thanks for helping!!!!