本文整理汇总了Python中dazzle.core.table.Table.get_column方法的典型用法代码示例。如果您正苦于以下问题:Python Table.get_column方法的具体用法?Python Table.get_column怎么用?Python Table.get_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dazzle.core.table.Table
的用法示例。
在下文中一共展示了Table.get_column方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test4
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import get_column [as 别名]
def test4():
from dazzle.core.dataset import DataSet
from dazzle.core.table import Table
test_dir = os.path.join("/temp", "dazzle-test")
ds = DataSet(test_dir, force_create=True)
t = Table("t", ds, [("a", np.array([np.nan, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, np.nan]))])
ca = t.get_column("a")
print(ca.str_values(format="%.4f"))
示例2: test2
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import get_column [as 别名]
def test2():
from dazzle.core.dataset import DataSet
from dazzle.core.table import Table
test_dir = os.path.join("/temp", "dazzle-test")
ds = DataSet(test_dir, force_create=True)
t = Table("t", ds, [("a", np.int)])
ca = t.get_column("a")
#t.append({'a': np.random.randint(10000000, size=5*(10**8)).astype(np.int32)})
print(ca.__dict__)
示例3: test_add_join_column
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import get_column [as 别名]
def test_add_join_column(self):
ds = DataSet("/temp/dazzle-test", force_create=True)
t = Table("t", ds, [('a', np.array([10, 2, 3, 5, 4, 7, 1, 8, 6, 9])),
('c', np.array([100, 20, 30, 50, 40, 70, 10, 80, 60, np.nan]))])
a_ref = np.array([1, 5, 4, 5, 6, 4, 1, 1, 9, 7, 8, 4, 5, 5, 2, 2, 8, 5, 4, 20])
u = Table("u", ds, [('a', a_ref), ("y", a_ref * 10)])
u.get_column("a").ref_column = t.get_column("a")
t.rebuild({'a': np.int8, 'c': np.int8})
u.rebuild({'a': np.int8, 'y': np.int16})
u.add_reference_column(u.get_column("a"), t.get_column("a"))
# print(t.head(20))
# print(u.head(30))
u.add_join_column("result", [u.get_column("a_ref"), t.get_column("c")])
#print(u.head(30))
assert np.array_equal(u['result'],
[-128, 10, 50, 40, 50, 60, 40, 10, 10, -128, 70, 80, 40, 50, 50, 20, 20, 80, 50, 40, -128])
示例4: TestColumn
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import get_column [as 别名]
class TestColumn(unittest.TestCase):
def setUp(self):
self.a = [6, 4, 7, 4, 6, 9]
self.test_dir = os.path.join("/temp", "dazzle-test")
ds = DataSet(self.test_dir, force_create=True)
self.t = Table("t", ds, [("a", np.array([1, 3], dtype=np.int8)), ("x", np.array([2, 4], dtype=np.float))], force_create=True)
self.ca = self.t.get_column("a")
@raises(DazzleError)
def test_data_dir01(self):
"""no table associated"""
print(LiteralColumn("a", np.array([], np.int)).data_dir)
def test_data_dir02(self):
self.assertEqual(self.ca.data_dir, os.path.join(self.test_dir, "t", "a"))
@raises(DazzleError)
def test_carray01(self):
"""no table associated"""
print(LiteralColumn("a", np.array([], np.int)).carray)
def test_carray02(self):
assert_array_equal(self.ca.carray[:], [1, 3])
@raises(DazzleError)
def test_init01(self):
LiteralColumn("", [])
@raises(DazzleError)
def test_init02(self):
LiteralColumn("1a", [])
@raises(DazzleError)
def test_init03(self):
LiteralColumn("_a", [])
@raises(DazzleError)
def test_init04(self):
LiteralColumn("a", "XX")
@raises(DazzleError)
def test_init05(self):
LiteralColumn("a", self)
def test_init06(self):
assert_array_equal(self.ca.carray[:], [1, 3])
def test_len01(self):
self.assertEqual(len(self.ca), 2)
def test_position01(self):
self.t.append({'a': self.a, 'x': self.a})
self.assertEqual(self.ca.position, 0)
def test_position02(self):
self.t.append({'a': self.a, 'x': self.a})
self.assertEqual(self.t.get_column("x").position, 1)
def test_getitem01(self):
self.assertEqual(self.ca[0], 1)
def test_getitem02(self):
self.assertEqual(self.ca[1], 3)
@raises(IndexError)
def test_getitem03(self):
self.t.append({'a': self.a, 'x': self.a})
_ = self.ca[10]
def test_getitem04(self):
self.t.append({'a': self.a, 'x': self.a})
assert_array_equal(self.ca[:], self.ca.carray[:])
def test_getitem05(self):
self.t.append({'a': self.a, 'x': self.a})
assert_array_equal(self.ca[0:5], [1, 3, 6, 4, 7])
def test_setitem01(self):
self.ca[0] = 2
self.assertEqual(self.ca[0], 2)
assert_array_equal(self.ca.carray[:], [2, 3])
def test_append01(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.append(self.a)
assert_array_equal(self.ca.carray[:], [1, 3, 6, 4, 7, 4, 6, 9, 6, 4, 7, 4, 6, 9])
@raises(DazzleError)
def test_rename01(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.rename("")
@raises(DazzleError)
def test_rename02(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.rename("x")
def test_rename03(self):
self.ca.rename("b")
#.........这里部分代码省略.........
示例5: TestTable
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import get_column [as 别名]
#.........这里部分代码省略.........
test_dir = os.path.join("/temp/dazzle-test2")
ds2 = DataSet(test_dir, force_create=True)
Table.copy("_", ds2, "/temp/dazzle-test/t")
def test_copy04(self):
test_dir = os.path.join("/temp/dazzle-test2")
ds2 = DataSet(test_dir, force_create=True)
t = Table.copy("t", ds2, "/temp/dazzle-test/t")
assert_equal_table(t, self.ds.get_table("t"))
@raises(FileNotFoundError)
def test_from_csv01(self):
Table.from_csv("Category", self.ds, "/bim/bam/test.csv", usecols=['CategoryID', 'ParentCategoryID'], verbose=False)
@raises(ValueError)
def test_from_csv02(self):
Table.from_csv("Category", self.ds, "/temp/dazzle-test/dataset.json", usecols=['CategoryID', 'ParentCategoryID'], verbose=False)
@raises(DazzleError)
def test_from_csv03(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), verbose=False)
def test_from_csv04(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), delimiter='\t',
usecols=['CategoryID', 'ParentCategoryID'], verbose=False)
self.assertEqual(len(cat.ctable), 68)
self.assertEqual(len(cat.columns), 2)
def test_from_dataframe01(self):
df = pd.DataFrame({'a': [1,2], 'b': [3., 4.]})
v = Table.from_dataframe("v", self.ds, df)
self.assertEqual(len(v.ctable), 2)
def test_get_column01(self):
self.assertTrue(self.t.get_column("x") is None)
def test_get_column02(self):
self.assertEqual(self.t.get_column("a").name, "a")
@raises(ValueError)
def test_remove_column01(self):
self.t.remove_column("x")
def test_remove_column02(self):
self.t.remove_column("a")
self.assertTrue(self.t.get_column("a") is None)
self.assertEqual(self.t.columns[0], self.t.get_column("b"))
self.assertEqual(self.t.ctable.names[0], "b")
def test_to_dataframe01(self):
self.assertEqual(len(self.u.to_dataframe()), 2)
def test_append01(self):
self.t.append({'a': [1,2], 'b': [3., 4.]})
self.assert_table_content(self.t, {
'len': 2,
'columns': [('a', {'content': [1,2]}), ('b', {'content': [3., 4.]})]})
def test_append02(self):
self.t.append({'b': [3., 4.], 'a': [1,2]})
self.assert_table_content(self.t, {
'len': 2,
'columns': [('a', {'content': [1,2]}), ('b', {'content': [3., 4.]})]})
def test_append03(self):
self.t.append({'a': [5.4, 2], 'b': [3., 4.]})