Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove df rows if two column values are not matching

    import pandas as pd
    #creating temp df for example 

    details = {
        'Name' : ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi', 'Priya', 'Swapnil'],
        'Nick_Name' : ['Ankit', 'Aish', 'Shaurya', 'Shiv', 'Priya', 'Lucky'],
    }
      
    # creating a Dataframe object 
    df = pd.DataFrame(details, columns = ['Name', 'Nick_Name',],index = ['a', 'b', 'c', 'd', 'e', 'f'])
      
    
    index_names = df[ (df['Name'] == df['Nick_Name'])].index
    
    df.drop(index_names, inplace = True)
    print(df)
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 :: find median pandas 
Python :: for loop in python array 
Python :: python ip address increment 
Python :: import csv as dic 
Python :: Flatten List in Python Using NumPy concatenate 
Python :: Change Separator Value When Printing 
Python :: matplotlib custom legends 
Python :: cv2 and PIL BRG to RGB 
Python :: form field required in django views 
Python :: python manual elif 
Python :: pd.loc 
Python :: find rules of decision tree python 
Python :: check file existtnece python 
Python :: blender python get current filename 
Python :: smote on dataframe of feature 
Python :: python find index 
Python :: matplotlib boxplot change size of outliers 
Python :: message to dict protobuf 
Python :: pandas to_csv hebrew 
Python :: iterate rows and columns dataframe 
Python :: spacy create tokenizer 
Python :: viewset and router 
Python :: even in python 
Python :: python extraer ultimo elemento lista 
Python :: standard streams with python3 
Python :: django insert data into database foreign key view.py 
Python :: decision tree 
Python :: how to take dynamic input in python 
Python :: combinations 
Python :: Exiting from python Command Line 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =