I am trying to use df.to\_csv() to append data to a csv. I would like to use an elegant code to use that, however an issue occurs. From time to time, I happened to get dictionary with keys with different order

```
import pandas as pd

# Simplified version of my function
def save_to_csv(dictionary, index):
    df = pd.DataFrame(dictionary, index=[index])
    header = index == 0
    df.to_csv('test.csv', mode='a', header=header)

# I run some function, I get dict 'dict' => I want to save it into csv file
id = 0
dict = {'col_name_1': 1, 'col_name_2': 2, 'col_name_3': 3}
save_to_csv(dict, id)

# I run some function a second time, I get dict 'dict' => I want to append it into csv file
id = 1
dict = {'col_name_2': 2, 'col_name_3': 3, 'col_name_1': 1}
save_to_csv(dict, id)

# etc ...

```

I get 

```
,col_name_1,col_name_2,col_name_3
0,1,2,3
1,2,3,1

```

Instead of 

```
,col_name_1,col_name_2,col_name_3
0,1,2,3
1,1,2,3

```

I would like to use this function for an extended period of time, so I would like to avoids hacks and have more of a clean/robust solution if possible

If you have some idea that would be very appreciated, thank you!