本文整理汇总了Python中pandas.sparse.api.SparseDataFrame.get_dtype_counts方法的典型用法代码示例。如果您正苦于以下问题:Python SparseDataFrame.get_dtype_counts方法的具体用法?Python SparseDataFrame.get_dtype_counts怎么用?Python SparseDataFrame.get_dtype_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.sparse.api.SparseDataFrame
的用法示例。
在下文中一共展示了SparseDataFrame.get_dtype_counts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSparseDataFrame
# 需要导入模块: from pandas.sparse.api import SparseDataFrame [as 别名]
# 或者: from pandas.sparse.api.SparseDataFrame import get_dtype_counts [as 别名]
#.........这里部分代码省略.........
y.ix[:9998] = 0
# TODO: y_sparse is unsused...fix
y_sparse = y.to_sparse(fill_value=0) # noqa
# without sparse value raises error
# df2 = SparseDataFrame([x2_sparse, y])
def test_constructor_preserve_attr(self):
# GH 13866
arr = pd.SparseArray([1, 0, 3, 0], dtype=np.int64, fill_value=0)
self.assertEqual(arr.dtype, np.int64)
self.assertEqual(arr.fill_value, 0)
df = pd.SparseDataFrame({'x': arr})
self.assertEqual(df['x'].dtype, np.int64)
self.assertEqual(df['x'].fill_value, 0)
s = pd.SparseSeries(arr, name='x')
self.assertEqual(s.dtype, np.int64)
self.assertEqual(s.fill_value, 0)
df = pd.SparseDataFrame(s)
self.assertEqual(df['x'].dtype, np.int64)
self.assertEqual(df['x'].fill_value, 0)
df = pd.SparseDataFrame({'x': s})
self.assertEqual(df['x'].dtype, np.int64)
self.assertEqual(df['x'].fill_value, 0)
def test_dtypes(self):
df = DataFrame(np.random.randn(10000, 4))
df.ix[:9998] = np.nan
sdf = df.to_sparse()
result = sdf.get_dtype_counts()
expected = Series({'float64': 4})
tm.assert_series_equal(result, expected)
def test_shape(self):
# GH 10452
self.assertEqual(self.frame.shape, (10, 4))
self.assertEqual(self.iframe.shape, (10, 4))
self.assertEqual(self.zframe.shape, (10, 4))
self.assertEqual(self.fill_frame.shape, (10, 4))
def test_str(self):
df = DataFrame(np.random.randn(10000, 4))
df.ix[:9998] = np.nan
sdf = df.to_sparse()
str(sdf)
def test_array_interface(self):
res = np.sqrt(self.frame)
dres = np.sqrt(self.frame.to_dense())
tm.assert_frame_equal(res.to_dense(), dres)
def test_pickle(self):
def _test_roundtrip(frame, orig):
result = self.round_trip_pickle(frame)
tm.assert_sp_frame_equal(frame, result)
tm.assert_frame_equal(result.to_dense(), orig, check_dtype=False)
_test_roundtrip(SparseDataFrame(), DataFrame())
self._check_all(_test_roundtrip)