Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.rpow()
函數返回級數和其他元素級的 index 冪(二進製運算符rsub)。相當於other ** series
,但支持用fill_value代替輸入之一中的丟失數據。
用法: Series.rpow(other, level=None, fill_value=None, axis=0)
參數:
other:序列或標量值
fill_value:填寫現有的缺失(NaN)值
level:在一個級別上廣播,在傳遞的MultiIndex級別上匹配索引值
返回:結果:係列
範例1:采用Series.rpow()
函數將標量值提高到給定Series對象中每個元素的冪。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.rpow()
函數將標量提高到給定係列對象的每個元素的冪。
# raise 2 to the power of each element in
# the sr object
selected_items = sr.rpow(other = 2)
# Print the returned Series object
print(selected_items)
輸出:
正如我們在輸出中看到的,Series.rpow()
函數已成功返回序列對象,這是取冪運算的結果。
範例2:采用Series.rpow()
函數將標量值提高到給定Series對象中每個元素的冪。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, None, 22.78, None, 20.124, None, 18.1002, None])
# Print the series
print(sr)
輸出:
現在我們將使用Series.rpow()
函數將標量提高到給定係列對象的每個元素的冪。我們將在所有缺失值的位置替換100。
# raise 2 to the power of each element in
# the sr object
selected_items = sr.rpow(other = 2, fill_value = 100)
# Print the returned Series object
print(selected_items)
輸出:
正如我們在輸出中看到的,Series.rpow()
函數已成功返回序列對象,這是取冪運算的結果。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Series.str.len()用法及代碼示例
- Python Pandas.factorize()用法及代碼示例
- Python Pandas TimedeltaIndex.name用法及代碼示例
- Python Pandas dataframe.ne()用法及代碼示例
- Python Pandas Series.between()用法及代碼示例
- Python Pandas DataFrame.where()用法及代碼示例
- Python Pandas Series.add()用法及代碼示例
- Python Pandas.pivot_table()用法及代碼示例
- Python Pandas Series.mod()用法及代碼示例
- Python Pandas Dataframe.at[ ]用法及代碼示例
- Python Pandas Dataframe.iat[ ]用法及代碼示例
- Python Pandas.pivot()用法及代碼示例
- Python Pandas dataframe.mul()用法及代碼示例
- Python Pandas.melt()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.rpow()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。