【发布时间】:2020-12-30 03:53:17
【问题描述】:
我正在使用 python 3.8 和 Pandas_schema 对数据运行完整性检查。我要求workflow_next_step 永远不能与workflow_entry_step 相同。我正在尝试生成一个比较两列的 CustomSeriesValidation,因为我没有看到执行此操作的股票函数。
有没有办法使用 Pandas_Schema 比较同一行中的两个单元格值?在此示例中,Pandas_Schema 将为 Mary 返回错误,因为她已从 In Progress 移动到 In Progress。
df = config.pd.DataFrame({
'prospect': ['Bob', 'Jill', 'Steve', 'Mary'],
'value': [10000, 15000, 500, 50000],
'workflow_entry_step': ['New', 'In Progress', 'Closed', 'In Progress'],
'workflow_next_step': ['In Progress', 'Closed' ,None, 'In Progress']})
schema = Schema([
Column('prospect', [LeadingWhitespaceValidation(), TrailingWhitespaceValidation()]),
Column('value', [CanConvertValidation(int),'Doesn\'t convert to integer.']),
Column('workflow_entry_step', [InListValidation([None,'New','In Progress','Closed'])]),
Column('workflow_next_step', [CustomSeriesValidation(lambda x: x != Column('workflow_entry_step'), InListValidation([None,'New','In Progress','Closed'])]), 'Steps cannot be the same.')])
【问题讨论】:
标签: python-3.x pandas dataframe validation schema