I am trying to create a dictionary from a CSV with 3 columns where the first two columns become the key and the third column becomes the value:
In this example, example.csv contains:
Column-1 Column-2 Column-3
1 A foo
2 B bar
The expected output should be:
dictionary = {1, A: foo, 2, B: bar}
I am currently attempting to import from a pandas dataframe and convert to a dictionary. I am using the following unsuccessfully:
df = pd.read_csv("example.csv")
dictionary = df.set_index(['Column-1', 'Column-2']).to_dict()
Is there a way to do this using pandas to create the dictionary or is there a more elegant way to convert the csv to a dictionary?