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.mod() is used to return the remainder after division of two numbers
Syntax: Series.mod(other, axis=’columns’, level=None, fill_value=None)
other: other series or list type to be divided and checked for remainder with caller series
fill_value: Value to be replaced by NaN in series/list before operation
level: integer value of level in case of multi index
Return type: Caller series with mod values ( caller series [i] % other series [i] )
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: Checking remainder
In this example, 5 rows of data frame are extracted using
head() method. A series is created from a Python list using Pandas
Series() method. The
mod() method is called on new short data frame and the created list is passed as other parameter.
As shown in output image, remainder after division of values at same index in caller series and other series was returned. Since nothing was passed to fill_value parameter, the Null values are returned as it is.
Example #2: Handling Null Values
Just like in the above example, same steps are done but this time a variable is created and some random value is passed to it. The value is then passed as fill_value parameter to
As shown in output image, null values were replaced by 21218 and all operations were done with that value. Hence, instead of NaN, 21218 % 3 = 2 was returned at 3rd position.
- Python | pandas.to_markdown() in Pandas
- Python | pandas.map()
- Python | Pandas Dataframe.at[ ]
- Python | Pandas Series.eq()
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas Series.ptp()
- Python | Pandas Series.pop()
- Python | Pandas Series.last()
- Python | Pandas Series.mean()
- Python | Pandas dataframe.add()
- Python | Pandas dataframe.div()
- Python | Pandas Series.take()
- Python | Pandas Series.agg()
- Python | Pandas Series.std()
- Python | Pandas dataframe.mean()
- Python | Pandas dataframe.max()
- Python | Pandas Index.contains()
- Python | Pandas DataFrame.abs()
- Python | Pandas dataframe.all()
- Python | Pandas Series.sem()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.