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


Python testing.SubclassedSparseDataFrame方法代码示例

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


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

示例1: test_subclass_sparse_to_frame

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import SubclassedSparseDataFrame [as 别名]
def test_subclass_sparse_to_frame(self):
        s = tm.SubclassedSparseSeries([1, 2], index=list('ab'), name='xxx')
        res = s.to_frame()

        exp_arr = pd.SparseArray([1, 2], dtype=np.int64, kind='block',
                                 fill_value=0)
        exp = tm.SubclassedSparseDataFrame({'xxx': exp_arr},
                                           index=list('ab'),
                                           default_fill_value=0)
        tm.assert_sp_frame_equal(res, exp)

        # create from int dict
        res = tm.SubclassedSparseDataFrame({'xxx': [1, 2]},
                                           index=list('ab'),
                                           default_fill_value=0)
        tm.assert_sp_frame_equal(res, exp)

        s = tm.SubclassedSparseSeries([1.1, 2.1], index=list('ab'),
                                      name='xxx')
        res = s.to_frame()
        exp = tm.SubclassedSparseDataFrame({'xxx': [1.1, 2.1]},
                                           index=list('ab'))
        tm.assert_sp_frame_equal(res, exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_subclass.py

示例2: test_subclass_sparse_slice

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import SubclassedSparseDataFrame [as 别名]
def test_subclass_sparse_slice(self):
        rows = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
        ssdf = tm.SubclassedSparseDataFrame(rows)
        ssdf.testattr = "testattr"

        tm.assert_sp_frame_equal(ssdf.loc[:2],
                                 tm.SubclassedSparseDataFrame(rows[:3]))
        tm.assert_sp_frame_equal(ssdf.iloc[:2],
                                 tm.SubclassedSparseDataFrame(rows[:2]))
        tm.assert_sp_frame_equal(ssdf[:2],
                                 tm.SubclassedSparseDataFrame(rows[:2]))
        assert ssdf.loc[:2].testattr == "testattr"
        assert ssdf.iloc[:2].testattr == "testattr"
        assert ssdf[:2].testattr == "testattr"

        tm.assert_sp_series_equal(ssdf.loc[1],
                                  tm.SubclassedSparseSeries(rows[1]),
                                  check_names=False,
                                  check_kind=False)
        tm.assert_sp_series_equal(ssdf.iloc[1],
                                  tm.SubclassedSparseSeries(rows[1]),
                                  check_names=False,
                                  check_kind=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_subclass.py

示例3: test_subclass_sparse_to_frame

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import SubclassedSparseDataFrame [as 别名]
def test_subclass_sparse_to_frame(self):
        s = tm.SubclassedSparseSeries([1, 2], index=list('abcd'), name='xxx')
        res = s.to_frame()

        exp_arr = pd.SparseArray([1, 2], dtype=np.int64, kind='block',
                                 fill_value=0)
        exp = tm.SubclassedSparseDataFrame({'xxx': exp_arr},
                                           index=list('abcd'),
                                           default_fill_value=0)
        tm.assert_sp_frame_equal(res, exp)

        # create from int dict
        res = tm.SubclassedSparseDataFrame({'xxx': [1, 2]},
                                           index=list('abcd'),
                                           default_fill_value=0)
        tm.assert_sp_frame_equal(res, exp)

        s = tm.SubclassedSparseSeries([1.1, 2.1], index=list('abcd'),
                                      name='xxx')
        res = s.to_frame()
        exp = tm.SubclassedSparseDataFrame({'xxx': [1.1, 2.1]},
                                           index=list('abcd'))
        tm.assert_sp_frame_equal(res, exp) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:test_subclass.py

示例4: test_subclass_sparse_slice

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import SubclassedSparseDataFrame [as 别名]
def test_subclass_sparse_slice(self):
        rows = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
        ssdf = tm.SubclassedSparseDataFrame(rows)
        ssdf.testattr = "testattr"

        tm.assert_sp_frame_equal(ssdf.loc[:2],
                                 tm.SubclassedSparseDataFrame(rows[:3]))
        tm.assert_sp_frame_equal(ssdf.iloc[:2],
                                 tm.SubclassedSparseDataFrame(rows[:2]))
        tm.assert_sp_frame_equal(ssdf[:2],
                                 tm.SubclassedSparseDataFrame(rows[:2]))
        assert ssdf.loc[:2].testattr == "testattr"
        assert ssdf.iloc[:2].testattr == "testattr"
        assert ssdf[:2].testattr == "testattr"

        tm.assert_sp_series_equal(ssdf.loc[1],
                                  tm.SubclassedSparseSeries(rows[1]),
                                  check_names=False)
        tm.assert_sp_series_equal(ssdf.iloc[1],
                                  tm.SubclassedSparseSeries(rows[1]),
                                  check_names=False) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:test_subclass.py

示例5: test_subclass_sparse_transpose

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import SubclassedSparseDataFrame [as 别名]
def test_subclass_sparse_transpose(self):
        ossdf = tm.SubclassedSparseDataFrame([[1, 2, 3],
                                              [4, 5, 6]])
        essdf = tm.SubclassedSparseDataFrame([[1, 4],
                                              [2, 5],
                                              [3, 6]])
        tm.assert_sp_frame_equal(ossdf.T, essdf) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_subclass.py


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