Python|熊猫 dataframe.rfloordiv()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas dataframe.rfloordiv()函数用于数据帧和其他元素的整数除法(二元运算符rfloordiv)。此函数与执行其他 // 数据帧基本相同,但支持替换其中一个输入中的缺失数据。
Syntax: DataFrame.rfloordiv(other, axis=’columns’, level=None, fill_value=None)
Parameters :
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 level
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.
Returns : result : DataFrame
示例 #1:使用 rfloordiv()函数查找具有数据框的系列的整数除法。
Python3
# 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
Python3
# 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
Python3
df.rfloordiv(sr, axis = 1)
Python3
# 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)
让我们创建系列
Python3
# 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()函数来找到系列与数据框的整数除法。
Python3
df.rfloordiv(sr, axis = 1)
输出 :
在输出中,返回了一个数据帧,数据帧中沿列轴的所有元素划分了系列中的相应元素。示例 #2:使用 rfloordiv()函数执行一个数据帧与另一个数据帧的地板分割。
注意:这里的输入数据框除以调用函数dataframe.rfloordiv() 的数据框
Python3
# 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)
输出 :