I have the following task.

I have this data:

```
import pandas
import numpy as np
data = {'name':  ['Todd', 'Chris', 'Jackie', 'Ben', 'Richard', 'Susan', 'Joe', 'Rick'],
    'phone': [912341.0, np.nan , 912343.0, np.nan, 912345.0, 912345.0, 912347.0, np.nan],
    ' email': ['todd@gmail.com', 'chris@gmail.com', np.nan, 'ben@gmail.com', np.nan ,np.nan , 'joe@gmail.com', 'rick@gmail.com'],
    'most_visited_airport': ['Heathrow', 'Beijing', 'Heathrow', np.nan, 'Tokyo', 'Beijing', 'Tokyo', 'Heathrow'],
    'most_visited_place': ['Turkey', 'Spain',np.nan , 'Germany', 'Germany', 'Spain',np.nan , 'Spain']
    }
df = pandas.DataFrame(data)

```

What I have to do is for every feature column (most\_visited\_airport etc.) and its values (Heathrow, Beijing, Tokyo) I have to generate personal information and output it to a file.

E.g. If we look at most\_visited\_airport and Heathrow
I need to output three files containing the names, emails and phones of the people who visited the airport the most.

![enter image description here](https://i.stack.imgur.com/O3ALo.png)

![enter image description here](https://i.stack.imgur.com/x9aQ2.png)

Currently, I have this code to do the operation for both columns and all the values:

```
columns_to_iterate = [ x for x in df.columns if 'most' in x]
for each in df[columns_to_iterate]:
    values = df[each].dropna().unique()
    for i in values:
        df1 = df.loc[df[each]==i,'name']
        df2 = df.loc[df[each]==i,' email']
        df3 = df.loc[df[each]==i,'phone']
        df1.to_csv(f'{each}_{i}_{df1.name}.csv')
        df2.to_csv(f'{each}_{i}_{df2.name}.csv')
        df3.to_csv(f'{each}_{i}_{df3.name}.csv')

```

Is it possible to do this in a more elegant and maybe faster way? Currently I have small dataset but not sure if this code will perform well with big data. My particular concern are the nested loops.

Thank you in advance!