当前位置: 首页>>代码示例>>Python>>正文


Python DataFrame.attach方法代码示例

本文整理汇总了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])
开发者ID:marsja,项目名称:pyvttbl,代码行数:49,代码来源:test_df_attach.py

示例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])
开发者ID:marsja,项目名称:pyvttbl,代码行数:23,代码来源:test_df_attach.py


注:本文中的pyvttbl.DataFrame.attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。