Ashraf Miah
Apr 18, 2022

--

This is possibly the worst way to use `pandas` for this application. A

A `DataFrame` is not a list, it has a certain structure to optimise it for vector operations to avoid looping.

What you're doing, is looping through each entry of a `pandas.Series` (from `df[ 'Country' ]`), storing the market in a separate list and then adding it back into the `DataFrame`.

The `pandas` way to do it is something like this:

```
if df['Country'] == 'Germany': df['Market'] = 'DACH'
```

Then repeat for the rest of the parameters. There are neater ways to write this but you get the idea.

--

--

Ashraf Miah

CTO, Data Scientist & Chartered Engineer (MEng CEng EUR ING MRAeS) with over 20 years experience in the Aerospace, Rail & Energy Industry.