本文整理汇总了Python中pandas.core.api.Series.combineFirst方法的典型用法代码示例。如果您正苦于以下问题:Python Series.combineFirst方法的具体用法?Python Series.combineFirst怎么用?Python Series.combineFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.api.Series
的用法示例。
在下文中一共展示了Series.combineFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_combineFirst
# 需要导入模块: from pandas.core.api import Series [as 别名]
# 或者: from pandas.core.api.Series import combineFirst [as 别名]
def test_combineFirst(self):
series = Series(common.makeIntIndex(20).astype(float),
index=common.makeIntIndex(20))
series_copy = series * 2
series_copy[::2] = np.NaN
# nothing used from the input
combined = series.combineFirst(series_copy)
self.assert_(np.array_equal(combined, series))
# Holes filled from input
combined = series_copy.combineFirst(series)
self.assert_(np.isfinite(combined).all())
self.assert_(np.array_equal(combined[::2], series[::2]))
self.assert_(np.array_equal(combined[1::2], series_copy[1::2]))
# mixed types
index = common.makeStringIndex(20)
floats = Series(common.randn(20), index=index)
strings = Series(common.makeStringIndex(10), index=index[::2])
combined = strings.combineFirst(floats)
common.assert_dict_equal(strings, combined, compare_keys=False)
common.assert_dict_equal(floats[1::2], combined, compare_keys=False)
# corner case
s = Series([1., 2, 3], index=[0, 1, 2])
result = s.combineFirst(Series([], index=[]))
assert_series_equal(s, result)