Python Pandas dataframe.rfloordiv()
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python软件包的奇妙生态系统。Pandas就是这些包中的一个,使导入和分析数据变得更加容易。
Pandas dataframe.rfloordiv()函数用于数据框架和其他元素的整数除法(二进制运算符rfloordiv)。这个函数本质上与做其他//数据框架相同,但支持替代其中一个输入中的缺失数据。
语法: DataFrame.rfloordiv(other, axis=’columns’, level=None, fill_value=None)
参数 :
other:系列,数据框架,或常数
axis:对于系列输入,axis要与系列的索引相匹配。
level :跨层广播,与通过的MultiIndex层的索引值相匹配。
fill_value : 在计算前用这个值填充现有的缺失(NaN)值,以及成功的DataFrame对齐所需的任何新元素。如果两个对应的DataFrame位置的数据都缺失,结果将是缺失。
返回 : result : DataFrame
例子#1:使用rfloordiv()函数来寻找一个带有数据帧的系列的整数除数。
# 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.rfloordiv()函数来寻找系列与dataframe的整数除法。
df.rfloordiv(sr, axis = 1)
输出 :
在输出中,已经返回了一个数据框架,所有的元素沿着数据框架中的列axis划分了系列中的相应元素。
示例#2:使用rfloordiv()函数对一个数据框架和另一个数据框架进行底层划分。
注意:这里输入的数据框架被调用函数dataframe.rfloordiv()的数据框架分割。
# 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"])
# divide df2 by df1
df1.rfloordiv(df2)
输出 :