Python | Панды dataframe.mod ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas dataframe.mod() function returns modulo of dataframe and other, element-wise (binary operator mod). This function is essentially same as the Dataframe % other, but with support to substitute a fill_value for missing data in one of the inputs. This function can be used with either a series or a dataframe.
Syntax: DataFrame.mod(other, axis=’columns’, level=None, fill_value=None)
Parameters :
Other : Series, DataFrame, or constant
axis : For Series input, axis to match Series index on
level : Broadcast across a level, matching Index values on the passed MultiIndex level
fill_value : Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missingReturns : result : DataFrame
Example #1: Use mod() function to find the modulo of each value in the dataframe withe a constant.
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[12, 4, 5, 44, 1], "B":[5, 2, 54, 3, 2], "C":[20, 16, 7, 3, 8], "D":[14, 3, 17, 2, 6]}) # Print the dataframedf |

Lets use the dataframe.mod() function to find the modulo of dataframe with 3
# find mod of dataframe values with 3df.mod(3) |
Output :
Example #2: Use mod() function to find the modulo with a series over the column axis.
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[12, 4, 5, 44, 1], "B":[5, 2, 54, 3, 2], "C":[20, 16, 7, 3, 8], "D":[14, 3, 17, 2, 6]}) # Print the dataframedf |

Let’s create the series object
# create a seiressr = pd.Series([3, 2, 4, 5]) # setting its column index similar to the dataframesr.index =["A", "B", "C", "D"] # print the seriessr |

Lets use the dataframe.mod() function to find the modulo of dataframe with series
# find mod of dataframe values with series# axis = 1 indicates column axisdf.mod(sr, axis = 1) |
Выход :

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.