本文整理汇总了Python中pandas.core.sparse.SparseSeries.astype方法的典型用法代码示例。如果您正苦于以下问题:Python SparseSeries.astype方法的具体用法?Python SparseSeries.astype怎么用?Python SparseSeries.astype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.sparse.SparseSeries
的用法示例。
在下文中一共展示了SparseSeries.astype方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSparseSeries
# 需要导入模块: from pandas.core.sparse import SparseSeries [as 别名]
# 或者: from pandas.core.sparse.SparseSeries import astype [as 别名]
#.........这里部分代码省略.........
assert_sp_series_equal(s4, self.zbseries)
# Sparse time series works
date_index = DateRange('1/1/2000', periods=len(self.bseries))
s5 = SparseSeries(self.bseries, index=date_index)
self.assert_(isinstance(s5, spm.SparseTimeSeries))
# pass Series
bseries2 = SparseSeries(self.bseries.to_dense())
assert_equal(self.bseries.sp_values, bseries2.sp_values)
# pass dict?
# don't copy the data by default
values = np.ones(len(self.bseries.sp_values))
sp = SparseSeries(values, sparse_index=self.bseries.sp_index)
sp.sp_values[:5] = 97
self.assert_(values[0] == 97)
# but can make it copy!
sp = SparseSeries(values, sparse_index=self.bseries.sp_index,
copy=True)
sp.sp_values[:5] = 100
self.assert_(values[0] == 97)
def test_constructor_ndarray(self):
pass
def test_constructor_nonnan(self):
arr = [0, 0, 0, nan, nan]
sp_series = SparseSeries(arr, fill_value=0)
assert_equal(sp_series.values, arr)
def test_copy_astype(self):
cop = self.bseries.astype(np.float_)
self.assert_(cop is not self.bseries)
self.assert_(cop.sp_index is self.bseries.sp_index)
self.assert_(cop.dtype == np.float64)
cop2 = self.iseries.copy()
assert_sp_series_equal(cop, self.bseries)
assert_sp_series_equal(cop2, self.iseries)
# test that data is copied
cop.sp_values[:5] = 97
self.assert_(cop.sp_values[0] == 97)
self.assert_(self.bseries.sp_values[0] != 97)
# correct fill value
zbcop = self.zbseries.copy()
zicop = self.ziseries.copy()
assert_sp_series_equal(zbcop, self.zbseries)
assert_sp_series_equal(zicop, self.ziseries)
# no deep copy
view = self.bseries.copy(deep=False)
view.sp_values[:5] = 5
self.assert_((self.bseries.sp_values[:5] == 5).all())
def test_astype(self):
self.assertRaises(Exception, self.bseries.astype, np.int64)
def test_kind(self):
self.assertEquals(self.bseries.kind, 'block')