Functions

Math

EXP

# How to Use Excel's EXP, POWER Function in Pandas

Excel's EXP function calculates the exponential of a given number, using the constant 'e' as the base. This function plays a vital role in various fields such as finance, engineering, and statistics.

This page explains how to use Excel's EXP function in Python using pandas.

## Implementing the Exponential and Power function in Pandas#

To replicate the EXP or POWER function in Excel using Python and pandas, here are some common implementations:

### Applying EXP to a single value#

To calculate the exponential of a single number in Excel, you would use the formula =EXP(number).

In pandas, you can use the numpy library's exp function to accomplish the same task

```
import numpy as np
result = np.exp(2)
```

### Use Mito's EXP, POWER function

Mito is an open source library that lets you write Excel formulas in Python. Either write the formula directly in Python or use the EXP, POWER formula in the Mito Spreadsheet and generate the equivalent Python code automatically.

Mito's EXP, POWER function works exactly like it does in Excel. That means you don't need worry about managing data types, handling errors, or the edge case differences between Excel and Python formulas.

Install Mito to start using Excel formulas in Python.

```
# Import the mitosheet Excel functions
from mitosheet.public.v3 import *;
# Use Mito's EXP, POWER function
df['Exponential'] = EXP(df['number'])
```

### Applying EXP to an entire column#

To calculate the exponential of an entire column in Excel, you would drag the EXP formula, =EXP(A1) dragged down the entire column.

In pandas, apply the numpy exp function to the whole column:

```
import numpy as np
df['Exponential'] = np.exp(df['number'])
```

### Applying POWER to a single value#

Unlike the EXP function, the POWER function in Excel allows you to specify the base of the exponent. To calculate the exponential of a single number in Excel, you would use the formula =POWER(number, power).

In Python, you can use the built in `**` operator. For example, to calculate 2 to the power of 3:

`result = 2 ** 3`

### Applying POWER to an entire column#

To calculate the exponential of an entire column in Excel, you would drag the POWER formula, =POWER(A1, power) dragged down the entire column.

In pandas, apply the built in `pow` function to the whole column. For example, to calculate the cube of each number in the 'number' column:

`df['Exponential'] = df['number'] ** 3`

### Applying POWER to an entire column with a variable exponent#

If instead of using a constant value as the exponent, like 3, you want to use a value from another column, you can use the apply function to apply the `pow` function to each row of the dataframe.

`df['Exponential'] = df['number'] ** df['power']`

## Common mistakes when using EXP, POWER in Python#

While using the EXP function in pandas, certain mistakes are commonly made. Here are some and how to rectify them.

### Using Log Base 10#

It's easy to confuse the natural logarithm (base 'e') with the logarithm base 10. Remember that np.exp uses base e, not base 10.

## Understanding the Exponential and Power Formula in Excel#

The EXP function in Excel takes a single argument and returns 'e' raised to the power of that number.

=EXP(number)

### EXP, POWER Excel Syntax

Parameter | Description | Data Type |
---|---|---|

number | The exponent to which the constant 'e' is raised. | number |

### Examples

Formula | Description | Result |
---|---|---|

=EXP(1) | Calculate the exponential of 1. | 2.71828182845905 |

=EXP(0) | Calculate the exponential of 0. | 1 |

**Don't re-invent the wheel. Use Excel formulas in Python.**

## Don't want to re-implement Excel's functionality in Python?

## Edit a spreadsheet.

Generate Python.

Mito is the easiest way to write Excel formulas in Python. Every edit you make in the Mito spreadsheet is automatically converted to Python code.

View all 100+ transformations →