예제 #1
0
def test_pandas(regtest):
    import pandas
    from emzed.core.data_types import Table
    data = dict(a=[1, 2, 3], b=[1.0, 2.0, None], c=["a", "b", "c"], d=[1.0, 2.0, 3.0],
                e=[None, None, None])
    df = pandas.DataFrame(data, columns=sorted(data.keys()))
    t = Table.from_pandas(df, formats={"b": "%.2f", float: "%.1f", object: "%s", None: "%s"})

    t.print_()
    t.print_(out=regtest)
예제 #2
0
파일: load_utils.py 프로젝트: kanzy/emzed2
def loadExcel(path=None, sheetname=0, types=None, formats=None):
    """`sheetname` is either an intger or string for indicating the sheet which will be extracted
    from the .xls or .xlsx file. The index 0 refers to the first sheet.

    `types` is either None or a dictionary mapping column names to their types.

    `formats` is either None or a dictionary mapping column names to formats.
    """
    path = _prepare_path(path, extensions=["xls", "xlsx"])
    if path is None:
        return None

    from emzed.core.data_types import Table
    import pandas

    # sheetname is reuqired for pandas < 0.14.0, later versions have default 0
    df = pandas.read_excel(path, sheetname=sheetname)
    return Table.from_pandas(df, types=types, formats=formats)
예제 #3
0
def test_pandas(regtest):
    import pandas
    from emzed.core.data_types import Table
    data = dict(a=[1, 2, 3],
                b=[1.0, 2.0, None],
                c=["a", "b", "c"],
                d=[1.0, 2.0, 3.0],
                e=[None, None, None])
    df = pandas.DataFrame(data, columns=sorted(data.keys()))
    t = Table.from_pandas(df,
                          formats={
                              "b": "%.2f",
                              float: "%.1f",
                              object: "%s",
                              None: "%s"
                          })

    t.print_()
    t.print_(out=regtest)
예제 #4
0
def test_pandas():
    import pandas
    import cStringIO
    from emzed.core.data_types import Table
    data = dict(a=[1, 2, 3], b=[1.0, 2.0, None], c=["a", "b", "c"], d=[1.0, 2.0, 3.0],
                e=[None, None, None])
    df = pandas.DataFrame(data, columns=sorted(data.keys()))
    t = Table.from_pandas(df, formats={"b": "%.2f", float: "%.1f", object: "%s", None: "%s"})
    out = cStringIO.StringIO()

    t.print_()
    t.print_(out=out)
    lines = out.getvalue().split("\n")

    assert len(lines) == 7
    assert lines[0].strip() == "a        b        c        d        e"
    assert lines[1].strip() == "int      float    str      float    None"
    assert lines[2].strip() == "------   ------   ------   ------   ------"
    assert lines[3].strip() == "1        1.00     a        1.0      -"
    assert lines[4].strip() == "2        2.00     b        2.0      -"
    assert lines[5].strip() == "3        -        c        3.0      -"