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.
Series.div() is used to divide series or list like objects with same length by the caller series.
Syntax: Series.div(other, level=None, fill_value=None, axis=0)
other: other series or list type to be divided by the caller series
fill_value: Value to be replaced by NaN in series/list before division
level: integer value of level in case of multi index
Return type: Caller series with divided values
To download the data set used in following example, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
Example #1: Dividing Series by list
In this example, the top 5 rows are stored in new variable using .head() method. After that a list of same length is created and the age column is divided by the list column using .div() method
As shown in the output image, it can be compared that the Divided age value column is having the Divided values of (Age)/(list).
Example #2: Dividing series by series having null values
In this example, the Salary column is divided by the Age column. Since the salary column contains null values too, by default it returns NaN no matter what is divided. In this example, 200000 is passed to replace null values with 200000.
As shown in the output image, the Divided values column has divided age column with 200000 in case of Null values.
- Python | pandas.to_markdown() in Pandas
- Add a Pandas series to another Pandas series
- Python | Pandas Index.insert()
- Python | Pandas DatetimeIndex.inferred_freq
- Python | Pandas PeriodIndex.start_time
- Python | Pandas PeriodIndex.week
- Python | Pandas Timestamp.second
- Python | Pandas Series.asobject
- Python | Pandas str.join() to join string/list elements with passed delimiter
- Python | Pandas DataFrame.reset_index()
- Python | Pandas dataframe.notna()
- Python | Pandas PeriodIndex.weekday
- Python | Pandas Series.dt.floor
- Python | Pandas Index.get_slice_bound()
- Python | Pandas Dataframe.duplicated()
- Python | Pandas dataframe.notnull()
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Use Pandas to Calculate Statistics in Python
- Python | Pandas Timestamp.date
- Python | Pandas Timestamp.ctime
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.