本文整理汇总了Python中pandas.core.api.Series.iloc[1]方法的典型用法代码示例。如果您正苦于以下问题:Python Series.iloc[1]方法的具体用法?Python Series.iloc[1]怎么用?Python Series.iloc[1]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.api.Series
的用法示例。
在下文中一共展示了Series.iloc[1]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_categorical_nans
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import iloc[1] [as 别名]
def test_categorical_nans(self):
s = Series(pd.Categorical(list('aaaaabbbcc'))) # 4,3,2,1 (nan)
s.iloc[1] = np.nan
result = s.value_counts()
expected = pd.Series([4, 3, 2], index=pd.CategoricalIndex(
['a', 'b', 'c'], categories=['a', 'b', 'c']))
tm.assert_series_equal(result, expected, check_index_type=True)
result = s.value_counts(dropna=False)
expected = pd.Series([
4, 3, 2, 1
], index=pd.CategoricalIndex(['a', 'b', 'c', np.nan]))
tm.assert_series_equal(result, expected, check_index_type=True)
# out of order
s = Series(pd.Categorical(
list('aaaaabbbcc'), ordered=True, categories=['b', 'a', 'c']))
s.iloc[1] = np.nan
result = s.value_counts()
expected = pd.Series([4, 3, 2], index=pd.CategoricalIndex(
['a', 'b', 'c'], categories=['b', 'a', 'c'], ordered=True))
tm.assert_series_equal(result, expected, check_index_type=True)
result = s.value_counts(dropna=False)
expected = pd.Series([4, 3, 2, 1], index=pd.CategoricalIndex(
['a', 'b', 'c', np.nan], categories=['b', 'a', 'c'], ordered=True))
tm.assert_series_equal(result, expected, check_index_type=True)
示例2: test_iloc_setitem_series
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import iloc[1] [as 别名]
def test_iloc_setitem_series(self):
s = Series(np.random.randn(10), index=range(0,20,2))
s.iloc[1] = 1
result = s.iloc[1]
self.assert_(result == 1)
s.iloc[:4] = 0
expected = s.iloc[:4]
result = s.iloc[:4]
assert_series_equal(result, expected)