Quantcast
Channel: Deleting DataFrame row in Pandas based on column value - Stack Overflow
Browsing latest articles
Browse All 20 View Live

Answer by Uwe Mayer for Deleting DataFrame row in Pandas based on column value

There are several answers in this thread involving the index, and most of those answers will not work if the index has duplicates. And yes, that has been pointed out in at least one of the comments...

View Article



Answer by cottontail for Deleting DataFrame row in Pandas based on column value

If you need to remove rows based on index values, the boolean indexing in the top answer may be adapted as well. For example, in the following code, rows where the index is between 3 and 7 are...

View Article

Answer by sdkayb for Deleting DataFrame row in Pandas based on column value

so many options provided(or maybe i didnt pay much attention to it, sorry if its the case), but no one mentioned this:we can use this notation in pandas: ~ (this gives us the inverse of the...

View Article

Image may be NSFW.
Clik here to view.

Answer by Gonçalo Peres for Deleting DataFrame row in Pandas based on column...

There are various ways to achieve that. Will leave below various options, that one can use, depending on specificities of one's use case.One will consider that OP's dataframe is stored in the variable...

View Article

Answer by Aniket Mukherjee for Deleting DataFrame row in Pandas based on...

You can try using this:df.drop(df[df.line_race != 0].index, inplace = True).

View Article


Answer by wisbucky for Deleting DataFrame row in Pandas based on column value

It doesn't make much difference for simple example like this, but for complicated logic, I prefer to use drop() when deleting rows because it is more straightforward than using inverse logic. For...

View Article

Answer by juan escorcia for Deleting DataFrame row in Pandas based on column...

Just in case you need to delete the row, but the value can be in different columns.In my case I was using percentages so I wanted to delete the rows which has a value 1 in any column, since that means...

View Article

Answer by ashkangh for Deleting DataFrame row in Pandas based on column value

One of the efficient and pandaic way is using eq() method:df[~df.line_race.eq(0)]

View Article


Answer by Mo_Offical for Deleting DataFrame row in Pandas based on column value

In case of multiple values and str dtypeI used the following to filter out given values in a col:def filter_rows_by_values(df, col, values): return df[~df[col].isin(values)]Example:In a DataFrame I...

View Article


Answer by Uzair for Deleting DataFrame row in Pandas based on column value

I compiled and run my code. This is accurate code. You can try it your own.data = pd.read_excel('file.xlsx')If you have any special character or space in column name you can write it in '' like in the...

View Article

Answer by Prateek Kumar Singh for Deleting DataFrame row in Pandas based on...

Just adding another way for DataFrame expanded over all columns:for column in df.columns: df = df[df[column]!=0]Example:def z_score(data,count): threshold=3 for column in data.columns: mean =...

View Article

Answer by Robvh for Deleting DataFrame row in Pandas based on column value

If you want to delete rows based on multiple values of the column, you could use:df[(df.line_race != 0) & (df.line_race != 10)]To drop all rows with values 0 and 10 for line_race.

View Article

Answer by Loochie for Deleting DataFrame row in Pandas based on column value

Though the previous answer are almost similar to what I am going to do, but using the index method does not require using another indexing method .loc(). It can be done in a similar but precise manner...

View Article


Answer by Amruth Lakkavaram for Deleting DataFrame row in Pandas based on...

Another way of doing it. May not be the most efficient way as the code looks a bit more complex than the code mentioned in other answers, but still alternate way of doing the same thing. df =...

View Article

Answer by desmond for Deleting DataFrame row in Pandas based on column value

just to add another solution, particularly useful if you are using the new pandas assessors, other solutions will replace the original pandas and lose the...

View Article


Answer by h3h325 for Deleting DataFrame row in Pandas based on column value

The given answer is correct nontheless as someone above said you can use df.query('line_race != 0') which depending on your problem is much faster. Highly recommend.

View Article

Answer by wonderkid2 for Deleting DataFrame row in Pandas based on column value

But for any future bypassers you could mention that df = df[df.line_race != 0] doesn't do anything when trying to filter for None/missing values.Does work:df = df[df.line_race != 0]Doesn't do...

View Article


Answer by Phillip Cloud for Deleting DataFrame row in Pandas based on column...

The best way to do this is with boolean masking:In [56]: dfOut[56]: line_date daysago line_race rating raw wrating0 2007-03-31 62 11 56 1.000 56.0001 2007-03-10 83 11 67 1.000 67.0002 2007-02-10 111 9...

View Article

Answer by tshauck for Deleting DataFrame row in Pandas based on column value

If I'm understanding correctly, it should be as simple as:df = df[df.line_race != 0]

View Article

Deleting DataFrame row in Pandas based on column value

I have the following DataFrame: daysago line_race rating rw wrating line_date 2007-03-31 62 11 56 1.000000 56.0000002007-03-10 83 11 67 1.000000 67.0000002007-02-10 111 9 66 1.000000...

View Article
Browsing latest articles
Browse All 20 View Live




Latest Images