本文整理汇总了Python中pandas.core.nanops.nansum方法的典型用法代码示例。如果您正苦于以下问题:Python nanops.nansum方法的具体用法?Python nanops.nansum怎么用?Python nanops.nansum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.nanops
的用法示例。
在下文中一共展示了nanops.nansum方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_apply
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_apply(frame):
applied = frame.apply(np.sqrt)
assert isinstance(applied, SparseDataFrame)
tm.assert_almost_equal(applied.values, np.sqrt(frame.values))
# agg / broadcast
with tm.assert_produces_warning(FutureWarning):
broadcasted = frame.apply(np.sum, broadcast=True)
assert isinstance(broadcasted, SparseDataFrame)
with tm.assert_produces_warning(FutureWarning):
exp = frame.to_dense().apply(np.sum, broadcast=True)
tm.assert_frame_equal(broadcasted.to_dense(), exp)
applied = frame.apply(np.sum)
tm.assert_series_equal(applied,
frame.to_dense().apply(nanops.nansum).to_sparse())
示例2: test_sum_inf
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_sum_inf(self):
s = Series(np.random.randn(10))
s2 = s.copy()
s[5:8] = np.inf
s2[5:8] = np.nan
assert np.isinf(s.sum())
arr = np.random.randn(100, 100).astype('f4')
arr[:, 2] = np.inf
with pd.option_context("mode.use_inf_as_na", True):
tm.assert_almost_equal(s.sum(), s2.sum())
res = nanops.nansum(arr, axis=1)
assert np.isinf(res).all()
示例3: test_apply
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_apply(frame):
applied = frame.apply(np.sqrt)
assert isinstance(applied, SparseDataFrame)
tm.assert_almost_equal(applied.values, np.sqrt(frame.values))
# agg / broadcast
with tm.assert_produces_warning(FutureWarning):
broadcasted = frame.apply(np.sum, broadcast=True)
assert isinstance(broadcasted, SparseDataFrame)
with tm.assert_produces_warning(FutureWarning):
exp = frame.to_dense().apply(np.sum, broadcast=True)
tm.assert_frame_equal(broadcasted.to_dense(), exp)
applied = frame.apply(np.sum)
tm.assert_series_equal(applied,
frame.to_dense().apply(nanops.nansum))
示例4: test_sum_inf
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_sum_inf(self):
s = Series(np.random.randn(10))
s2 = s.copy()
s[5:8] = np.inf
s2[5:8] = np.nan
assert np.isinf(s.sum())
arr = np.random.randn(100, 100).astype('f4')
arr[:, 2] = np.inf
with pd.option_context("mode.use_inf_as_na", True):
assert_almost_equal(s.sum(), s2.sum())
res = nanops.nansum(arr, axis=1)
assert np.isinf(res).all()
示例5: test_apply
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_apply(self):
applied = self.frame.apply(np.sqrt)
tm.assert_isinstance(applied, SparseDataFrame)
assert_almost_equal(applied.values, np.sqrt(self.frame.values))
applied = self.fill_frame.apply(np.sqrt)
self.assert_(applied['A'].fill_value == np.sqrt(2))
# agg / broadcast
broadcasted = self.frame.apply(np.sum, broadcast=True)
tm.assert_isinstance(broadcasted, SparseDataFrame)
assert_frame_equal(broadcasted.to_dense(),
self.frame.to_dense().apply(np.sum, broadcast=True))
self.assert_(self.empty.apply(np.sqrt) is self.empty)
from pandas.core import nanops
applied = self.frame.apply(np.sum)
assert_series_equal(applied,
self.frame.to_dense().apply(nanops.nansum))
示例6: test_apply
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_apply(self):
applied = self.frame.apply(np.sqrt)
assert isinstance(applied, SparseDataFrame)
tm.assert_almost_equal(applied.values, np.sqrt(self.frame.values))
applied = self.fill_frame.apply(np.sqrt)
assert applied['A'].fill_value == np.sqrt(2)
# agg / broadcast
broadcasted = self.frame.apply(np.sum, broadcast=True)
assert isinstance(broadcasted, SparseDataFrame)
exp = self.frame.to_dense().apply(np.sum, broadcast=True)
tm.assert_frame_equal(broadcasted.to_dense(), exp)
assert self.empty.apply(np.sqrt) is self.empty
from pandas.core import nanops
applied = self.frame.apply(np.sum)
tm.assert_series_equal(applied,
self.frame.to_dense().apply(nanops.nansum))
示例7: test_nansum
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_nansum(self):
self.check_funs(nanops.nansum, np.sum, allow_str=False,
allow_date=False, allow_tdelta=True, check_dtype=False,
empty_targfunc=np.nansum)
示例8: test_nansum_buglet
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_nansum_buglet(self):
ser = Series([1.0, np.nan], index=[0, 1])
result = np.nansum(ser)
tm.assert_almost_equal(result, 1)
示例9: sum
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def sum(self, axis=None, dtype=None, out=None, keepdims=False,
initial=None, skipna=True, min_count=0):
nv.validate_sum((), dict(dtype=dtype, out=out, keepdims=keepdims,
initial=initial))
return nanops.nansum(self._ndarray, axis=axis, skipna=skipna,
min_count=min_count)
示例10: test_nansum_buglet
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_nansum_buglet(self):
s = Series([1.0, np.nan], index=[0, 1])
result = np.nansum(s)
assert_almost_equal(result, 1)
示例11: test_nansum
# 需要导入模块: from pandas.core import nanops [as 别名]
# 或者: from pandas.core.nanops import nansum [as 别名]
def test_nansum(self):
self.check_funs(nanops.nansum, np.sum, allow_str=False,
allow_date=False, allow_tdelta=True, check_dtype=False)