Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
 
PREVIOUS NEXT
Tagged: #remove #df #rows #column #values #matching
ADD COMMENT
Topic
Name
5+2 =