bigframes.pandas.DataFrame.applymap#

DataFrame.applymap(func,na_action:str|None=None)DataFrame#

Apply a function to a Dataframe elementwise.

This method applies a function that accepts and returns a scalarto every element of a DataFrame.

Note

In pandas 2.1.0, DataFrame.applymap is deprecated and renamed toDataFrame.map.

Examples:

Let’s usereuse=False flag to make sure a newremote_functionis created every time we run the following code, but you can skip itto potentially reuse a previously deployedremote_function fromthe same user defined function.

>>>@bpd.remote_function(reuse=False,cloud_function_service_account="default")...defminutes_to_hours(x:int)->float:...returnx/60
>>>df_minutes=bpd.DataFrame(...{"system_minutes":[0,30,60,90,120],..."user_minutes":[0,15,75,90,6]})>>>df_minutessystem_minutes  user_minutes0               0             01              30            152              60            753              90            904             120             6[5 rows x 2 columns]
>>>df_hours=df_minutes.map(minutes_to_hours)>>>df_hourssystem_minutes  user_minutes0             0.0           0.01             0.5          0.252             1.0          1.253             1.5           1.54             2.0           0.1[5 rows x 2 columns]

If there areNA/None values in the data, you can ignoreapplying the remote function on such values by specifyingna_action='ignore'.

>>>df_minutes=bpd.DataFrame(...{..."system_minutes":[0,30,60,None,90,120,pd.NA],..."user_minutes":[0,15,75,90,6,None,pd.NA]...},dtype="Int64")>>>df_hours=df_minutes.map(minutes_to_hours,na_action='ignore')>>>df_hourssystem_minutes  user_minutes0             0.0           0.01             0.5          0.252             1.0          1.253            <NA>           1.54             1.5           0.15             2.0          <NA>6            <NA>          <NA>[7 rows x 2 columns]
Parameters:
  • func (function) – Python function wrapped byremote_function decorator,returns a single value from a single value.

  • na_action (Optional[str],default None) –{None,'ignore'}, default None. Ifignore, propagate NaNvalues, without passing them to func.

Returns:

Transformed DataFrame.

Return type:

bigframes.pandas.DataFrame

Raises:
  • TypeError – If value provided forfunc is not callable.

  • ValueError – If value provided forna_action is notNone orignore.

This Page