search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
Pandas
655 guides
keyboard_arrow_down
check_circle
Mark as learned
thumb_up
0
thumb_down
0
chat_bubble_outline
0
Comment
auto_stories Bi-column layout
settings

# Pandas DataFrame | rpow method

schedule Aug 11, 2023
Last updated
local_offer
PythonPandas
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Pandas `DataFrame.rpow(~)` method computes the exponential power of a scalar, sequence, Series or DataFrame and the values in the source DataFrame, that is:

``` other ** DataFrame ```

Note that this is just the reverse of `pow(~)` method, which does:

``` DataFrame ** other ```
NOTE

Unless you use the parameters `axis`, `level` and `fill_value`, `rpow(~)` is equivalent to computing the exponential power using the `**` operator.

# Parameters

1. `other`link | `scalar` or `sequence` or `Series` or `DataFrame`

The resulting DataFrame will be the exponential power of `other` and the source DataFrame.

2. `axis`link | `int` or `string` | `optional`

Whether to broadcast `other` for each column or row of the source DataFrame:

Axis

Description

`"index"` or `0`

`other` is broadcasted for each column of the source DataFrame.

`"columns"` or `1`

`other` is broadcasted for each row of the source DataFrame.

This is only relevant if the shape of the source DataFrame and that of `other` does not match. By default, `axis=1`.

3. `level` | `int` or `string` | `optional`

The name or the integer index of the level to consider. This is relevant only if your DataFrame is Multi-index.

4. `fill_value`link | `float` or `None` | `optional`

The value to replace `NaN` before computing the exponential power. If the computation involves two `NaN`, then its result would still be `NaN`. By default, `fill_value=None`.

# Return Value

A new `DataFrame` computed by the exponential power of the source DataFrame and `other`.

# Examples

## Basic usage

Consider the following DataFrames:

``` df = pd.DataFrame({"A":[3,4], "B":[5,6]})df_other = pd.DataFrame({"A":[1,1], "B":[2,2]}) [df] | [df_other] A B | A B0 3 5 | 0 1 21 4 6 | 1 1 2 ```

Computing the exponential power of `df` and `df_other`:

``` df.rpow(df_other) A B0 1 321 1 64 ```

Here, we're computing the following element-wise exponential power:

``` 1**3 2**51**4 2**6 ```

Consider the following DataFrame:

``` df = pd.DataFrame({"A":[3,4], "B":[5,6]})df A B0 3 51 4 6 ```

### Row-wise

By default, `axis=1`, which means that `other` will be broadcasted for each row in `df`:

``` df.rpow([1,2]) # axis=1 A B0 1 321 1 64 ```

Here, we're computing the following element-wise exponential power:

``` 1**3 2**51**4 2**6 ```

### Column-wise

To broadcast `other` for each column in `df`, set `axis=0` like so:

``` df.rpow([1,2], axis=0) A Ba 1 1b 16 64 ```

Here, we're computing the following element-wise exponential power:

``` 1**3 1**52**4 2**6 ```

## Specifying fill_value

Consider the following DataFrames:

``` df = pd.DataFrame({"A":[2,np.NaN], "B":[np.NaN,3]})df_other = pd.DataFrame({"A":[4,5], "B":[np.NaN,np.NaN]}) A B | A B0 2.0 NaN | 0 4 NaN1 NaN 3.0 | 1 5 NaN ```

By default, when we compute the power using `rpow(~)`, any operation with `NaN` results in `NaN`:

``` df.rpow(df_other) A B0 16.0 NaN1 NaN NaN ```

We can fill the `NaN` values before we compute the power by using the `fill_value` parameter:

``` df.rpow(df_other, fill_value=1) A B0 16.0 NaN1 5.0 1.0 ```

Here, notice when the operation is between two `NaN`, the result would still be `NaN` regardless of `fill_value`.

Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!