提供帮助函数,帮助将行为表转换为pandas数据帧,反之亦然。
behave-pandas的Python项目详细描述
表现熊猫
用于Behavebdd测试框架的实用程序包,用于转换小黄瓜表 往返于pandas数据帧很轻松。
生成状态
安装
pip install behave-pandas
功能
- 轻松地将小黄瓜表转换为具有显式数据类型信息的pandas数据帧
- 轻松地将pandas数据帧转换为behave pandas可以解析的behave表
- 支持在列或行上转换具有多个索引级别的数据帧
- 处理支持它的数据类型丢失的数据。
API
behave pandas api非常简单,由两个函数组成:
frombehave_pandasimporttable_to_dataframe,dataframe_to_table
示例
Feature: Table printer as a tester I want to be able to create gherkin tables from existing data framesScenario: simple index Given a gherkin table as input | str | float | str | | index_col | float_col | str_col | | egg | 3.0 | silly walks | | spam | 4.1 | spanish inquisition | | bacon | 5.2 | dead parrot |When converted to a data frame using 1 row as column names and 1 column as indexAnd printed using data_frame_to_tableThen it prints a valid string copy pasteable into gherkin files""" | object | float64 | object | | index_col | float_col | str_col | | egg | 3.0 | silly walks | | spam | 4.1 | spanish inquisition | | bacon | 5.2 | dead parrot |"""
相关步骤:
frombehaveimport*frombehave_pandasimporttable_to_dataframe,dataframe_to_tableuse_step_matcher("parse")@when('converted to a data frame using {column_levels:d} row as column names and {index_levels:d} column as index')defstep_impl(context,column_levels,index_levels):context.parsed=table_to_dataframe(context.input,column_levels=column_levels,index_levels=index_levels)@then("it prints a valid string copy pasteable into gherkin files")defstep_impl(context):assertcontext.result==context.text@step("printed using data_frame_to_table")defstep_impl(context):context.result=dataframe_to_table(context.parsed)
分析的数据帧:
>>> context.parsed
float_col str_col
index_col
egg 3.0 silly walks
spam 4.1 spanish inquisition
bacon 5.2 dead parrot
>>> context.parsed.info()
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, egg to bacon
Data columns (total 2 columns):
float_col 3 non-null float64
str_col 3 non-null object
dtypes: float64(1), object(1)
memory usage: 72.0+ bytes