0

I need to delete rows from a dataframe which have "No" value in column Auto-Investment. How to do that using pandas dataframe?

index = 0
    for x in df3['Auto-Investment']:
        if x == 'No':
            rows = df3.index(index)
            df3.drop(rows, inplace=True)
        index += 1    
    print(df3)   
Levsha
  • 63
  • 9

3 Answers3

2

try this:

df3 = df3[df3['Auto-Investment'] != 'No']
I'mahdi
  • 23,382
  • 5
  • 22
  • 30
  • @Levsha if this work see this link : https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – I'mahdi Sep 02 '21 at 10:51
1

You can do it by deselecting the ones that are 'no'.

df3 = df3[df3['Auto-Investment']!='No']
Babak Fi Foo
  • 926
  • 7
  • 17
1

Number of solutions:

1. df3 = df3[df3['Auto-Investment']!='No]

2. df3.drop(df3['Auto-Investment']!='No].index, inplace=True)

Discussion on which solution is better: Pandas drop rows vs filter

Niv Dudovitch
  • 1,614
  • 7
  • 15