For others like me, I come up with this question, but I want to do the following: Create a dict row by row to display a column based on the value of the neighboring column.
Here is our chart table:
Rating y 0 AAA 19 1 AA1 18 2 AA2 17 3 AA3 16 4 A1 15 5 A2 14 6 A3 13 ... 19 D 0
IN:
import pandas as pd df_map.set_index('y') df_map.transpose() dict_y = df_map['Rating'].to_dict()
OF:
{19: 'AAA', 18: 'AA1', 17: 'AA2', 16: 'AA3', 15: 'A1', 14: 'A2', 13: 'A3', 12: 'BBB1', 11: 'BBB2', 10: 'BBB3', 9: 'BB1', 8: 'BB2', 7: 'BB3', 6: 'B1', 5: 'B2', 4: 'B3', 3: 'CCC1', 2: 'CCC2', 1: 'D'}
source share