当先锋百科网

首页 1 2 3 4 5 6 7

dataframe多个索引条件出现错误ValueError: cannot reindex from a duplicate axis一种解决方案
出错代码:

age_mr = data_train[data_train['Name'].str.contains('Mr\.')][data_train['Age'].notnull()]['Age'].mean()

该出错代码单独运行没问题,但是放在子函数中,会报错:ValueError: cannot reindex from a duplicate axis

修改后代码:

    age_mr = df[df['Name'].str.contains('Mr\.')].Age.notnull().mean()