- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to divide a pandas series with scalar using series.div() method?
In the pandas series constructor, the div() or divide() method is used to perform element-wise floating division operation between the two series objects or between a series and a scalar.
The method returns a series with resultant floating division values. We can also do the division operation between series and scalar.
Here we will see some examples for dividing a series with a scalar.
import pandas as pd # create pandas Series series = pd.Series([13,48,6,72,8]) print("Series object:",series) # divide print("combined series:",series.div(2))
In this example, we will divide the Series with a scalar value “2”. Initially, we have created a pandas series object using a list of integer values. After that, we performed the division operation.
Series object: 0 13 1 48 2 6 3 72 4 8 dtype: int64 combined series: 0 6.5 1 24.0 2 3.0 3 36.0 4 4.0 dtype: float64
In the above block, we can see both initial and resultant series objects. The element-wise division operation is performed between series elements and scaler value “2”.
import pandas as pd # create pandas Series series = pd.Series([13,48,6,72,8]) print("Series object:",series) # divide print("combined series:",series.div([1,2,3,4,5]))
Initially, we have created a pandas Series using a python list of integer values. And applied the div() method with a list of scalar values.
Series object: 0 13 1 48 2 6 3 72 4 8 dtype: int64 combined series: 0 13.0 1 24.0 2 2.0 3 18.0 4 1.6 dtype: float64
The Series.div() method returns a series with floating division values.
- How to combine a pandas Series with Scalar using Series.combine() method?
- How does pandas series div() method work?
- How to apply integer division to the pandas series by a scalar?
- How to sort a Pandas Series?
- How does pandas series astype() method work?
- How does pandas series combine() method work?
- How does pandas series combine_first() method work?
- How to remove a specified row From the Pandas Series Using Drop() method?
- How to create a series from a list using Pandas?
- How to append a pandas Series object to another Series in Python?
- How does the pandas Series idxmax() method work?
- How does the pandas Series idxmin() method work?
- How to append elements to a Pandas series?
- How to access Pandas Series elements by using indexing?
- How to remove NaN from a Pandas Series?