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)
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)
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)
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 -"