0

I want to find specific rows in a huge dataframe and assign a comment if the condition is met.

The part of the code I use is as follows:

def check_car(x):
        if x['CAR'] == 'FERRARI' and x['COUNTRY'] != 'ITALY':
            return 'This is wrong'
        else:
            x.drop()

After that I use this function to create new data frame with ID and comment. The new data frame contain IDs with “This is wrong” as well as None values. Instead of that I want to remove all None values from data frame, is it possible to do that in the function itself?

I used x.drop but I got the error:

ValueError: ("Need to specify at least one of 'labels', 'index' or 'columns'”)
Umar.H
  • 22,559
  • 7
  • 39
  • 74
Pietaq
  • 31
  • 1
  • 4

1 Answers1

0

First pick all the columns satisfying your condition, then assign them values. Try:

df = df.loc[ (df['CAR'] == 'FERRARI') & (df['COUNTRY'] != 'ITALY')]
df.loc["COLUMN" ] = "This is wrong"
hacker315
  • 1,996
  • 2
  • 13
  • 23
  • I tried that one but how to attach to column with comments the next column with IDs from original data frame for which the condition is satisfied? – Pietaq Jun 12 '19 at 11:22