> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# error: nothing to repeat at position 0 - Pandas
- URL: https://datascientyst.com/error-nothing-to-repeat-at-position-0-pandas/
- Published: 2023-09-04T14:18:09.000Z
- Updated: 2023-09-04T14:18:09.000Z
- Author: John D K
- Tags: Pandas Error

Common Pandas error - error: nothing to repeat at position 0 can be result of several operations:

- bad regular expression
- reading CSV file with incorrect separator

## Fix error: nothing to repeat at position 0

To fix error:

> error: nothing to repeat at position 0

First we need to identify what is the reason for this error.  
Once we know the reason the solutions might be:

- change - `.str.contains('?')` to `.str.contains('?', regex=False)`
- change the `read_csv()` sepators, encoding etc:  
  - `, sep='\t', engine='python', encoding='ISO-8859-1'`

## Data

Suppose we have data like the one below:

```python
from faker import Faker
import pandas as pd

Faker.seed(0)
fake = Faker()
addr = []
for _ in range(5):
	addr.append(fake.address())
df = pd.DataFrame({'address':addr})

```

|   | address                                              |
| - | ---------------------------------------------------- |
| 0 | 48764 Howard Forge Apt. 421\\nVanessaside, VT 79393  |
| 1 | PSC 4115, Box 7815\\nAPO AA 41945                    |
| 2 | 778 Brown Plaza\\nNorth Jenniferfurt, VT 88077       |
| 3 | 3513 John Divide Suite 115\\nRodriguezside, LA 93111 |
| 4 | 398 Wallace Ranch Suite 593\\nIvanburgh, AZ 80818    |

## Example - bad regex

If we try to search for a question mark we will end with Pandas error: **error: nothing to repeat at position 0.**

```python
df['address'].str.contains('?')

```

The solution is either to escape the question mark or use `regex=False`:

```python
df['address'].str.contains('\?')
df['address'].str.contains('?', regex=False)

```

## Fix - read\_csv

To fix the same error if we get it during reading CSV file by method `read_csv` file we can use parameters like:

```python
pd.read_csv('data.csv', sep=''\*,\*'' , engine='python', encoding='ISO-8859-1')

```

Why do we get this error for read\_csv? The reason is that some characters are special and treated in a different way. So we may need to escape them:

> addition, separators longer than 1 character and different from '\\s+' will be interpreted as regular expressions and will also force the use of the Python parsing engine. Note that regex delimiters are prone to ignoring quoted data. Regex example: '\\r\\t'.

## Output

![](https://datascientyst.com/content/images/2023/09/error-nothing-to-repeat-at-position-0-pandas.webp)

## Resources

- [pandas.read\_csv](https://pandas.pydata.org/docs/reference/api/pandas.read%5Fcsv.html?ref=datascientyst.com)
- [pandas.Series.str.contains](https://pandas.pydata.org/docs/reference/api/pandas.Series.str.contains.html?ref=datascientyst.com)