Python Forum
Drop a row if it contains a certain value in pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop a row if it contains a certain value in pandas
#1
I have this text file:

LEU,LEID,PPP,YYY,LEO
'1','2','3','4','5'
'2','1','2','3','4'
'2','AA','','',''

I want to delete the rows where for LEID='1'

I wrote this code:
import pandas as pd

#import numpy
import os

originalFile=os.path.abspath("D:\\python\\test\\OriginalFile.csv")
df = pd.read_csv(originalFile)
#df.drop(df.LEID == '1')


df=df[df.LEID != '1']

df.to_csv('D:\\python\\test\\CorrectedFile.csv')
print (df)
Why the row with LEID='1' is not delted?
Reply


Messages In This Thread
Drop a row if it contains a certain value in pandas - by deltanov - Nov-07-2018, 09:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to drop column in pandas SriMekala 3 3,000 Aug-26-2019, 06:36 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020