本文整理汇总了Python中pyvttbl.DataFrame.attach方法的典型用法代码示例。如果您正苦于以下问题:Python DataFrame.attach方法的具体用法?Python DataFrame.attach怎么用?Python DataFrame.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvttbl.DataFrame
的用法示例。
在下文中一共展示了DataFrame.attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_attach
# 需要导入模块: from pyvttbl import DataFrame [as 别名]
# 或者: from pyvttbl.DataFrame import attach [as 别名]
class Test_attach(unittest.TestCase):
def test0(self):
self.df1=DataFrame()
self.df1.read_tbl('data/words~ageXcondition.csv')
with self.assertRaises(Exception) as cm:
self.df1.attach('s')
self.assertEqual(str(cm.exception),
'second argument must be a DataFrame')
def test1(self):
self.df1=DataFrame()
self.df2=DataFrame()
self.df1.read_tbl('data/words~ageXcondition.csv')
self.df2.read_tbl('data/words~ageXcondition.csv')
# add an extra key to df1
self.df1['EXTRA'] = [5 for a in self.df1['AGE']]
with self.assertRaises(Exception) as cm:
self.df1.attach(self.df2)
self.assertEqual(str(cm.exception),
'self and other must have the same columns')
def test2(self):
df1=DataFrame()
df2=DataFrame()
df1.read_tbl('data/words~ageXcondition.csv')
df2.read_tbl('data/words~ageXcondition.csv')
M=df1.shape()[1]
# this should work
df1.attach(df2)
# df1 should have twice as many rows now
self.assertEqual(df1.shape()[1]/2,df2.shape()[1])
# go through and check data
for i in range(M):
for n in df1.keys():
if _isfloat(df1[n][i]):
self.assertAlmostEqual(df1[n][i],df1[n][M+i])
else:
self.assertEqual(df1[n][i],df1[n][M+i])
示例2: test2
# 需要导入模块: from pyvttbl import DataFrame [as 别名]
# 或者: from pyvttbl.DataFrame import attach [as 别名]
def test2(self):
df1=DataFrame()
df2=DataFrame()
df1.read_tbl('data/words~ageXcondition.csv')
df2.read_tbl('data/words~ageXcondition.csv')
M=df1.shape()[1]
# this should work
df1.attach(df2)
# df1 should have twice as many rows now
self.assertEqual(df1.shape()[1]/2,df2.shape()[1])
# go through and check data
for i in range(M):
for n in df1.keys():
if _isfloat(df1[n][i]):
self.assertAlmostEqual(df1[n][i],df1[n][M+i])
else:
self.assertEqual(df1[n][i],df1[n][M+i])