提供帮助函数,帮助将行为表转换为pandas数据帧,反之亦然。

behave-pandas的Python项目详细描述


表现熊猫

用于Behavebdd测试框架的实用程序包,用于转换小黄瓜表 往返于pandas数据帧很轻松。

生成状态

Travis CI badge

安装

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jframe为什么JAVA paint()方法不起作用?   java Guice:将ContainerRequestContext注入拦截器   java如何优雅地关闭Spring JMS MessageListenerAdapter   java如何在Spring中设置快照隔离级别   Java中的安卓平台独立信任存储路径   java无法在eclipse中运行hello world程序   java Sinch空指针问题   使用Java将JSON流式传输到BigQuery   java从“大数据”中选择什么Swing控件?   java通过对象字段过滤/排序集合?   java将数据从活动传递到另一个活动中的片段   java访问打包在jar文件中的文档   Java获取事件的大小。getDragboard()。getFiles()。流()。映射(文件::长度)。toString());   java Android libgdx:启动程序图标按下后,启动屏幕不会立即显示   java如何在Google App Engine灵活环境中配置oracle jdk   java有没有办法减少这些行?   Java:客户端socket不读取第二行,在终止符行之后保持打开状态   java以编程方式获取api 29上的所有APK文件   java ActionBar按钮不显示