Convert dataframe to dictionary in python with column names

  dataframe, dictionary, python

This is the dataframe that I am using.

     Product  January  February  March  April  May  June
 NR-DZ600MB       10        10     10     10   10    10
NR-F654GT-XG      10        10     10     10   10    10
NU-SC300BYPQ      10        10     10     10   10    10
NU-SC180BYPQ      10        10     10     10   10    10
   SR-JQ105       10        10     10     10   10    10
  

The output I want to get is this

{(‘January’, ‘NR-DZ600MB’): 10, (‘January’, ‘NR-F654GT-XG’): 10, (‘January’, ‘NU-SC300BYPQ’): 10, (‘January’, ‘NU-SC180BYPQ’): 10, (‘February’, ‘NR-DZ600MB’): 15, (‘February’, ‘NR-F654GT-XG’): 20, (‘February’, ‘NU-SC300BYPQ’): 10, (‘February’, ‘NU-SC180BYPQ’): 10, (‘March’, ‘NR-DZ600MB’): 10, (‘March’, ‘NR-F654GT-XG’): 10, (‘March’, ‘NU-SC300BYPQ’): 10, (‘March’, ‘NU-SC180BYPQ’): 10….}

How am I suppose to do it?

Source: Python Questions

LEAVE A COMMENT