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


Python testing.makeDataFrame方法代码示例

本文整理汇总了Python中pandas.util.testing.makeDataFrame方法的典型用法代码示例。如果您正苦于以下问题:Python testing.makeDataFrame方法的具体用法?Python testing.makeDataFrame怎么用?Python testing.makeDataFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.makeDataFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_explicit

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_write_explicit(self, compression, get_random_path):
        base = get_random_path
        path1 = base + ".compressed"
        path2 = base + ".raw"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to compressed file
            df.to_pickle(p1, compression=compression)

            # decompress
            with tm.decompress_file(p1, compression=compression) as f:
                with open(p2, "wb") as fh:
                    fh.write(f.read())

            # read decompressed file
            df2 = pd.read_pickle(p2, compression=None)

            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_pickle.py

示例2: test_write_infer

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_write_infer(self, ext, get_random_path):
        base = get_random_path
        path1 = base + ext
        path2 = base + ".raw"
        compression = None
        for c in self._compression_to_extension:
            if self._compression_to_extension[c] == ext:
                compression = c
                break

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to compressed file by inferred compression method
            df.to_pickle(p1)

            # decompress
            with tm.decompress_file(p1, compression=compression) as f:
                with open(p2, "wb") as fh:
                    fh.write(f.read())

            # read decompressed file
            df2 = pd.read_pickle(p2, compression=None)

            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_pickle.py

示例3: test_read_explicit

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_read_explicit(self, compression, get_random_path):
        base = get_random_path
        path1 = base + ".raw"
        path2 = base + ".compressed"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to uncompressed file
            df.to_pickle(p1, compression=None)

            # compress
            self.compress_file(p1, p2, compression=compression)

            # read compressed file
            df2 = pd.read_pickle(p2, compression=compression)

            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_pickle.py

示例4: test_sparse_frame

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_sparse_frame(self):

        s = tm.makeDataFrame()
        s.loc[3:5, 1:3] = np.nan
        s.loc[8:10, -2] = np.nan
        ss = s.to_sparse()

        self._check_roundtrip(ss, tm.assert_frame_equal,
                              check_frame_type=True)

        ss2 = s.to_sparse(kind='integer')
        self._check_roundtrip(ss2, tm.assert_frame_equal,
                              check_frame_type=True)

        ss3 = s.to_sparse(fill_value=0)
        self._check_roundtrip(ss3, tm.assert_frame_equal,
                              check_frame_type=True) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_packers.py

示例5: test_factory_fun

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_factory_fun(self):
        try:
            with get_store(self.path) as tbl:
                raise ValueError('blah')
        except ValueError:
            pass
        finally:
            safe_remove(self.path)

        try:
            with get_store(self.path) as tbl:
                tbl['a'] = tm.makeDataFrame()

            with get_store(self.path) as tbl:
                self.assertEquals(len(tbl), 1)
                self.assertEquals(type(tbl['a']), DataFrame)
        finally:
            safe_remove(self.path) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_pytables.py

示例6: test_versioning

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_versioning(self):

        with ensure_clean_store(self.path) as store:
            store['a'] = tm.makeTimeSeries()
            store['b'] = tm.makeDataFrame()
            df = tm.makeTimeDataFrame()
            _maybe_remove(store, 'df1')
            store.append('df1', df[:10])
            store.append('df1', df[10:])
            self.assert_(store.root.a._v_attrs.pandas_version == '0.10.1')
            self.assert_(store.root.b._v_attrs.pandas_version == '0.10.1')
            self.assert_(store.root.df1._v_attrs.pandas_version == '0.10.1')

            # write a file and wipe its versioning
            _maybe_remove(store, 'df2')
            store.append('df2', df)

            # this is an error because its table_type is appendable, but no version
            # info
            store.get_node('df2')._v_attrs.pandas_version = None
            self.assertRaises(Exception, store.select, 'df2') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_pytables.py

示例7: test_open_args

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_open_args(self):

        with ensure_clean_path(self.path) as path:

            df = tm.makeDataFrame()

            # create an in memory store
            store = HDFStore(path,mode='a',driver='H5FD_CORE',driver_core_backing_store=0)
            store['df'] = df
            store.append('df2',df)

            tm.assert_frame_equal(store['df'],df)
            tm.assert_frame_equal(store['df2'],df)

            store.close()

            # only supported on pytable >= 3.0.0
            if LooseVersion(tables.__version__) >= '3.0.0':

                # the file should not have actually been written
                self.assert_(os.path.exists(path) is False) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_pytables.py

示例8: test_sparse_frame

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_sparse_frame(self):

        s = tm.makeDataFrame()
        s.ix[3:5, 1:3] = np.nan
        s.ix[8:10, -2] = np.nan
        ss = s.to_sparse()

        self._check_double_roundtrip(ss, tm.assert_frame_equal,
                                     check_frame_type=True)

        ss2 = s.to_sparse(kind='integer')
        self._check_double_roundtrip(ss2, tm.assert_frame_equal,
                                     check_frame_type=True)

        ss3 = s.to_sparse(fill_value=0)
        self._check_double_roundtrip(ss3, tm.assert_frame_equal,
                                     check_frame_type=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_pytables.py

示例9: test_sparse_panel

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_sparse_panel(self):

        items = ['x', 'y', 'z']
        p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
        sp = p.to_sparse()

        self._check_double_roundtrip(sp, assert_panel_equal,
                                     check_panel_type=True)

        sp2 = p.to_sparse(kind='integer')
        self._check_double_roundtrip(sp2, assert_panel_equal,
                                     check_panel_type=True)

        sp3 = p.to_sparse(fill_value=0)
        self._check_double_roundtrip(sp3, assert_panel_equal,
                                     check_panel_type=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_pytables.py

示例10: test_legacy_table_write

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_legacy_table_write(self):
        raise nose.SkipTest("skipping for now")

        store = HDFStore(tm.get_data_path('legacy_hdf/legacy_table_%s.h5' % pandas.__version__), 'a')

        df = tm.makeDataFrame()
        wp = tm.makePanel()

        index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
                                   ['one', 'two', 'three']],
                           labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
                                   [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
                           names=['foo', 'bar'])
        df = DataFrame(np.random.randn(10, 3), index=index,
                       columns=['A', 'B', 'C'])
        store.append('mi', df)

        df = DataFrame(dict(A = 'foo', B = 'bar'),index=lrange(10))
        store.append('df', df, data_columns = ['B'], min_itemsize={'A' : 200 })
        store.append('wp', wp)

        store.close() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_pytables.py

示例11: test_sparse_frame

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_sparse_frame(self):

        s = tm.makeDataFrame()
        s.ix[3:5, 1:3] = np.nan
        s.ix[8:10, -2] = np.nan
        ss = s.to_sparse()

        self._check_roundtrip(ss, tm.assert_frame_equal,
                              check_frame_type=True)

        ss2 = s.to_sparse(kind='integer')
        self._check_roundtrip(ss2, tm.assert_frame_equal,
                              check_frame_type=True)

        ss3 = s.to_sparse(fill_value=0)
        self._check_roundtrip(ss3, tm.assert_frame_equal,
                              check_frame_type=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_packers.py

示例12: test_sparse_panel

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_sparse_panel(self):

        items = ['x', 'y', 'z']
        p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
        sp = p.to_sparse()

        self._check_roundtrip(sp, tm.assert_panel_equal,
                              check_panel_type=True)

        sp2 = p.to_sparse(kind='integer')
        self._check_roundtrip(sp2, tm.assert_panel_equal,
                              check_panel_type=True)

        sp3 = p.to_sparse(fill_value=0)
        self._check_roundtrip(sp3, tm.assert_panel_equal,
                              check_panel_type=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_packers.py

示例13: test_from_dict_mixed_orient

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_from_dict_mixed_orient(self):
        df = tm.makeDataFrame()
        df['foo'] = 'bar'

        data = {'k1': df, 'k2': df}

        panel = Panel.from_dict(data, orient='minor')

        assert panel['foo'].values.dtype == np.object_
        assert panel['A'].values.dtype == np.float64 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_panel.py

示例14: test_cache_updating

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_cache_updating(self):
        # GH 4939, make sure to update the cache on setitem

        df = tm.makeDataFrame()
        df['A']  # cache series
        df.ix["Hello Friend"] = df.ix[0]
        assert "Hello Friend" in df['A'].index
        assert "Hello Friend" in df['B'].index

        panel = tm.makePanel()
        panel.ix[0]  # get first item into cache
        panel.ix[:, :, 'A+1'] = panel.ix[:, :, 'A'] + 1
        assert "A+1" in panel.ix[0].columns
        assert "A+1" in panel.ix[1].columns

        # 10264
        df = DataFrame(np.zeros((5, 5), dtype='int64'), columns=[
                       'a', 'b', 'c', 'd', 'e'], index=range(5))
        df['f'] = 0
        df.f.values[3] = 1

        # TODO(wesm): unused?
        # y = df.iloc[np.arange(2, len(df))]

        df.f.values[3] = 2
        expected = DataFrame(np.zeros((5, 6), dtype='int64'), columns=[
                             'a', 'b', 'c', 'd', 'e', 'f'], index=range(5))
        expected.at[3, 'f'] = 2
        tm.assert_frame_equal(df, expected)
        expected = Series([0, 0, 0, 2, 0], name='f')
        tm.assert_series_equal(df.f, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_chaining_and_caching.py

示例15: test_reset_index

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeDataFrame [as 别名]
def test_reset_index(self):
        df = tm.makeDataFrame()[:5]
        ser = df.stack()
        ser.index.names = ['hash', 'category']

        ser.name = 'value'
        df = ser.reset_index()
        assert 'value' in df

        df = ser.reset_index(name='value2')
        assert 'value2' in df

        # check inplace
        s = ser.reset_index(drop=True)
        s2 = ser
        s2.reset_index(drop=True, inplace=True)
        tm.assert_series_equal(s, s2)

        # level
        index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]],
                           codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2],
                                  [0, 1, 0, 1, 0, 1]])
        s = Series(np.random.randn(6), index=index)
        rs = s.reset_index(level=1)
        assert len(rs.columns) == 2

        rs = s.reset_index(level=[0, 2], drop=True)
        tm.assert_index_equal(rs.index, Index(index.get_level_values(1)))
        assert isinstance(rs, Series) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:31,代码来源:test_alter_axes.py


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