📜  如果两列值不匹配,则删除 df 行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:43.506000             🧑  作者: Mango

代码示例2
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)