0

I have a data frame named df1 in python code:

    SYMBOL    TYPE          DATE       VALUE
0    ABC     Normal       29-03-2018     100
1    DEF     Artificial   30-03-2018      96
2    DEF     Normal       01-04-2018     105

and 5000 such rows

I want to delete rows containing TYPE = Artificial I wrote the following code but it gives an error

for i in df1:
    if df1['trade_type'] == 'Artificial':
        del df1[i]
print(df1)

It gives error as:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
jpp
  • 159,742
  • 34
  • 281
  • 339
doomsday
  • 45
  • 5

2 Answers2

0

Try with below:

df1 = df1.drop(df1[df1['TYPE'] == 'Artificial'].index)
Rehan Azher
  • 1,340
  • 1
  • 9
  • 17
0
import pandas as pd

data = '''\
SYMBOL    TYPE          DATE       VALUE
ABC     Normal       29-03-2018     100
DEF     Artificial   30-03-2018      96
DEF     Normal       01-04-2018     105'''

df = pd.read_csv(pd.compat.StringIO(data), sep='\s+')

# Create a mask
m = df.TYPE != 'Artificial'

# Reassign with mask
df = df.loc[m]
Anton vBR
  • 18,287
  • 5
  • 40
  • 46