I have following DataFrame parsed into Python:
df = pd.read_csv("my_file.csv")
result:
indexes X_values Y_values
0 IDX1 x1 y1
1 IDX1 x2 y2
2 IDX1 x3 y3
3 IDX1 x4 y4
6 IDX2 x1 y1
9 IDX2 x4 y4
10 IDX3 x1 y1
11 IDX3 x2 y2
I need to create dictionaries with each indexes as key and x_values & y_values as list of nested dictionaries. Output should be like:
{"IDX1" : [{"x1": "y1"}, {"x2": "y2"}, {"x3": "y3"}, {"x4": "y4"}],
"IDX2": [{"x1": "y1"},{"x4": "y4"}],
"IDX3":[{"x1": "y1"}, {"x2": "y2"}]}
I am trying to parse it using set_index() method but always missing something. Could you help me?
Also, dictionary of nested dictionaries with indexes as keys would be also good solution.