Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove rows if not matching with value in df

# Quick Examples

#Using drop() to delete rows based on column value
df.drop(df[df['Fee'] >= 24000].index, inplace = True)

# Remove rows
df2 = df[df.Fee >= 24000]

# If you have space in column name
# Specify column name with in single quotes
df2 = df[df['column name']]

# Using loc
df2 = df.loc[df["Fee"] >= 24000 ]

# Delect rows based on multiple column value
df2 = df[ (df['Fee'] >= 22000) & (df['Discount'] == 2300)]

# Drop rows with None/NaN
df2 = df[df.Discount.notnull()]
Comment

remove row if all are the same value pandas

print (df['S'] != df['T'])
0    False
1     True
2     True
3     True
4    False
5     True
6     True
7     True
8    False
dtype: bool

df = df[df['S'] != df['T']]
print (df)
   S  T  W           U
1  A  B  0  Undirected
2  A  C  1  Undirected
3  B  A  0  Undirected
5  B  C  1  Undirected
6  C  A  1  Undirected
7  C  B  1  Undirected
Comment

PREVIOUS NEXT
Code Example
Python :: last element in dictionary python 
Python :: cv2 load image 
Python :: create new thread python 
Python :: selenium get current url 
Python :: send dm discord py 
Python :: python cube turtle 
Python :: how to manually click button godot 
Python :: sort list by attribute python 
Python :: python remove empty folders 
Python :: install python decouple 
Python :: python pygame key input 
Python :: how to count down in python using turtle graphics 
Python :: pandas to csv encoding 
Python :: best free rat for windows 
Python :: python add current directory to import path 
Python :: creating an interface tkinter 
Python :: python matplotlib inline 
Python :: pandas date_range 
Python :: pandas create column from another column 
Python :: python f string decimal places 
Python :: debconf: falling back to frontend: Readline Configuring tzdata 
Python :: jupyter no output cell 
Python :: pandas split column into multiple columns by delimiter 
Python :: kmeans sklearn 
Python :: what is ycor in python turle 
Python :: how to print the text of varying length in python 
Python :: python input with space 
Python :: pandas get numeric columns 
Python :: pandas create new column 
Python :: how to leave some parameters in python and let the value be anything 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =