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.
dataframe.div() is used to find the floating division of the dataframe and other element-wise. This function is similar to
datafram/other, but with an additional support to handle missing value in one of the input data.
Syntax: DataFrame.div(other, axis=’columns’, level=None, fill_value=None)
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
div() function to find floating division of dataframe elements with a constant value. Also handle the
NaN value present in the dataframe.
Now find the division of each dataframe element with 2
The output is a dataframe with cells containing the result of the division of each cell value with 2. All the
NaN cells have been filled with 50 before performing the division.
Example #2: Use
div() function to find the floating division of a dataframe with a series object over the index axis.
Note: If the dimension of the index axis of the dataframe and the series object is not same then an error will occur.
Now, find the division of dataframe elements with the series object along the index axis
The output is a dataframe with cells containing the result of the division of the current cell element with the corresponding series object cell.
- Python | pandas.to_markdown() in Pandas
- Python | pandas.map()
- Python | Pandas Series.lt()
- Pandas Profiling in Python
- Python | Pandas Series.le()
- Python | Pandas Timestamp.day
- Python | Pandas Series.sum()
- Python | Pandas Series.abs()
- Python | Pandas Series.ge()
- Python | Pandas Index.where
- Python | Pandas DataFrame.loc
- Python | Pandas Series.mod()
- Python | Pandas Series.str.contains()
- Python | Pandas Series.ne()
- Python | Pandas Series.eq()
- Python | Pandas Dataframe.at[ ]
- Python | Pandas TimedeltaIndex.take()
- Python | Pandas.factorize()
- Python | Pandas dataframe.pow()
- Python | Pandas Series.str.len()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.