我有一个数据框 df, plan_year name metal_level_name0 20118 Gold Heritage Plus 1500 - 02 Gold1 2018 NaN Platinum2 2018 Gold Heritage Plus 2000 - 01 Gold我已经把数据验证上plan_year和name列下面喜欢,m4 = ((df['plan_year'].notnull()) & (df['plan_year'].astype(str).str.isdigit()) & (df['plan_year'].astype(str).str.len() == 4))m1 = (df1[['name']].notnull().all(axis=1))我得到了下面的有效数据框,df1 = df[m1 & m4]我可以获得 df1 中不存在的行(无效的行)merged = df.merge(df1.drop_duplicates(), how='outer', indicator=True)merged[merged['_merge'] == 'left_only']我想跟踪哪一行由于哪项验证而失败。我想获得一个包含所有无效数据数据框的数据框,如下所示 - plan_year name metal_level_name Failed message0 20118 Gold Heritage Plus 1500 - 02 Gold Failed due to wrong plan_year1 2018 NaN Platinum name column cannot be null有人可以帮我解决这个问题吗?
添加回答
举报
0/150
提交
取消