I have a dataframe (df), that is made up of several columns. One of these columns is called 'CODE', and is made up the names 'A', 'B', 'C', and 'D' that pop up many times throughout the rows. Essentially, my goal is to drop all rows 'D' is the name in the column 'CODE'. I know I can't do a simple drop, becasue i'm not trying to get rid of the column, i'm trying to remove any row that has this specific name in a certain column. I hope this makes some sense!
Asked
Active
Viewed 191 times
0
-
Please include (1) an example of the dataframe, (2) the expected output, and (3) your code that (presumably) did not work. – DYZ Jul 23 '18 at 19:31
-
`df = df[df['CODE']!='D']` – rahlf23 Jul 23 '18 at 19:31
-
Possible duplicate of [Select rows from a DataFrame based on values in a column in pandas](https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas) – ALollz Jul 23 '18 at 19:45
3 Answers
4
You can create a new dataframe that excludes all rows that have 'D' in the 'CODE' column:
df = df[df['CODE']!='D']

rahlf23
- 8,869
- 4
- 24
- 54
0
What about selecting all other rows that are not equal to that name you wanna discard?
df = df[df['CODE'] != 'D']

Matthias
- 5,574
- 8
- 61
- 121
-
Why the downvote? because I asked for acceptance? Anyway, the answer is correct and therefore a downvote isn't funny at all. – Matthias Jul 24 '18 at 08:00