Levsha
Levsha

Reputation: 43

pandas related problem regarding deleting data from a dataframe

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)   

Upvotes: 0

Views: 51

Answers (3)

Niv Dudovitch
Niv Dudovitch

Reputation: 1658

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

Upvotes: 1

Babak Fi Foo
Babak Fi Foo

Reputation: 1048

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

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

Upvotes: 1

I'mahdi
I'mahdi

Reputation: 24049

try this:

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

Upvotes: 2

Related Questions