##### Statement of Completion#10537933

##### Intro to Pandas for Data Analysis

medium

# Finding Mersenne primes with Pandas

Resolution

Activities

In [ ]:

```
import pandas as pd
import numpy as np
```

##### 1) Read the prime numbers from `primes1.csv`

into a dataframe named `primes_df`

¶

In [ ]:

```
primes_df = ...
```

### Generating "one less than powers of two"¶

Here's an example of how to check if a prime is a Mersenne prime programmatically:

In [ ]:

```
p = 31
```

In [ ]:

```
for i in range(1, p):
result = 2 ** i - 1
if result == p:
print(f"{p} is a Mersenne prime!")
break
elif result > p:
print(f"{p} is NOT a Mersenne prime :(")
break
```

`p`

until you understand how Mersenne primes are calculated. Next, let's find some M-primes using Pandas.

In [ ]:

```
100_000 ** 2
```

##### 2) Generate a DataFrame with a sequential list of integers¶

In [ ]:

```
exp_df = ...
```

##### 3) Create the column `2^n`

¶

In [ ]:

```
exp_df['2^n'] = ...
```

##### 4) Create the column `2^n - 1`

¶

In [ ]:

```
exp_df['2^n - 1'] = ...
```

### Finding Mersenne primes¶

##### 5) Create a new column `is_mersenne_prime`

that contains ALL `False`

values¶

In [ ]:

```
primes_df['is_mersenne_prime'] = ...
```

##### 6) Mark the Mersenne primes with a `True`

value¶

In [ ]:

```
```