Skip to content
Related Articles

Related Articles

Python | Pandas dataframe.floordiv()
  • Last Updated : 19 Nov, 2018

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas dataframe.floordiv() function is used for integer division of the dataframe with either a constant, series or any other dataframe.
If other is a series then, the dimension of series must match with the division axis of the dataframe. If other is a data frame then, both the dataframes should have the same dimension.

Equivalent to dataframe/other, but with support to substitute a fill_value for missing data in one of the inputs.

Syntax: DataFrame.floordiv(other, axis=’columns’, level=None, fill_value=None)

Parameters:
other : Series, DataFrame, or constant
axis : For Series input, axis to match Series index on
fill_value : Fill missing (NaN) values with this value. If both DataFrame locations are missing, the result will be missing
level : Broadcast across a level, matching Index values on the passed MultiIndex level



Returns : result : DataFrame

Example #1: Use floordiv() function to find the integer division of a dataframe with a constant. Dataframe constains NA value.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.DataFrame({"A":[5, 3, 6, 4],
                   "B":[11, None, 4, 3],
                   "C":[4, 3, 8, None],
                   "D":[5, 4, 2, 8]})
  
# Print the dataframe
df

chevron_right


Now apply the floordiv() function. In our dataframe we are having NA values. We fill all such values with 50.

filter_none

edit
close

play_arrow

link
brightness_4
code

# applying floordiv() function 
df.floordiv(2, fill_value = 50)

chevron_right


Output :

Notice, all the non-Na value in the dataframe has been filled with 50 before performing the integer division.
 
Example #2: Use floordiv() function to find the integer division of a dataframe with a Series.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.DataFrame({"A":[5, 3, 6, 4],
                   "B":[11, 2, 4, 3],
                   "C":[4, 3, 8, 5],
                   "D":[5, 4, 2, 8]})
  
# creating series
sr = pd.Series([2, 1, 3, 1])
  
# applying floordiv() function 
df.floordiv(sr, axis = 0)

chevron_right


Output :

Each row of the dataframe is divided by the corresponding value in the series object.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :