本文整理汇总了Python中pandas.core.api.Series.astype方法的典型用法代码示例。如果您正苦于以下问题:Python Series.astype方法的具体用法?Python Series.astype怎么用?Python Series.astype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.api.Series
的用法示例。
在下文中一共展示了Series.astype方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _nobs_raw
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import astype [as 别名]
def _nobs_raw(self):
if self._is_rolling:
window = self._window
else:
# expanding case
window = len(self._index)
result = Series(self._time_obs_count).rolling(window, min_periods=1).sum().values
return result.astype(int)
示例2: test_value_counts_normalized
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import astype [as 别名]
def test_value_counts_normalized(self):
# GH12558
s = Series([1, 2, np.nan, np.nan, np.nan])
dtypes = (np.float64, np.object, 'M8[ns]')
for t in dtypes:
s_typed = s.astype(t)
result = s_typed.value_counts(normalize=True, dropna=False)
expected = Series([0.6, 0.2, 0.2],
index=Series([np.nan, 2.0, 1.0], dtype=t))
tm.assert_series_equal(result, expected)
result = s_typed.value_counts(normalize=True, dropna=True)
expected = Series([0.5, 0.5],
index=Series([2.0, 1.0], dtype=t))
tm.assert_series_equal(result, expected)
示例3: _window_time_obs
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import astype [as 别名]
def _window_time_obs(self):
window_obs = Series(self._time_obs_count > 0).rolling(self._window, min_periods=1).sum().values
window_obs[np.isnan(window_obs)] = 0
return window_obs.astype(int)