Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas dataframe.rpow()
函數用於查找數據幀和其他逐元素(二進製運算符rfloordiv)的 index 冪。此函數與執行other ** dataframe
但支持替換其中一個輸入中的丟失數據。
用法:DataFrame.rpow(other, axis=’columns’, level=None, fill_value=None)
參數:
other: Series, DataFrame, or constant
axis: For Series input, axis to match Series index on
level: Broadcast across a level, matching Index values on the passed MultiIndex leve
fill_value: Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
返回值:結果:DataFrame
範例1:采用rpow()
函數將序列中的每個元素提升到列軸上 DataFrame 中的相應值。
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.DataFrame({"A":[1, 5, 3, 4, 2],
"B":[3, 2, 4, 3, 4],
"C":[2, 2, 7, 3, 4],
"D":[4, 3, 6, 12, 7]},
index =["A1", "A2", "A3", "A4", "A5"])
# Print the dataframe
df
讓我們創建係列
# importing pandas as pd
import pandas as pd
# Create the series
sr = pd.Series([12, 25, 64, 18], index =["A", "B", "C", "D"])
# Print the series
sr
讓我們使用dataframe.rpow()
函數將係列中的每個元素提升到 DataFrame 中相應元素的功效。
# equivalent to sr ** df
df.rpow(sr, axis = 1)
輸出:
範例2:采用rpow()
函數將 DataFrame 中的每個元素提升為其他 DataFrame 中的相應元素的冪
# importing pandas as pd
import pandas as pd
# Creating the first dataframe
df1 = pd.DataFrame({"A":[1, 5, 3, 4, 2],
"B":[3, 2, 4, 3, 4],
"C":[2, 2, 7, 3, 4],
"D":[4, 3, 6, 12, 7]},
index =["A1", "A2", "A3", "A4", "A5"])
# Creating the second dataframe
df2 = pd.DataFrame({"A":[10, 11, 7, 8, 5],
"B":[21, 5, 32, 4, 6],
"C":[11, 21, 23, 7, 9],
"D":[1, 5, 3, 8, 6]},
index =["A1", "A2", "A3", "A4", "A5"])
# Print the first dataframe
print(df1)
# Print the second dataframe
print(df2)
讓我們表演df2 ** df1
# raise df2 to the power of df1
df1.rpow(df2)
輸出:
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas dataframe.rpow()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。