I need to create a dictionary where the keys are a tuple of strings and the values are integers. I have done it using the CSV module but with pandas, I can better manage my data.
Basically I want this:
print(Supply)
{(1, 1): 400, (1, 2): 0, (2, 1): 1500, (2, 2): 0, (3, 1): 900, (3, 2): 0}
To become this:
print(Supply)
{('1', '1'): 400, ('1', '2'): 0, ('2', '1'): 1500, ('2', '2'): 0, ('3', '1'): 900, ('3', '2'): 0}
CodePudding user response:
This does the transformation you want:
Supply = {tuple(str(i) for i in key): val for key, val in Supply.items()}
print(Supply)
# {('1', '1'): 400, ('1', '2'): 0, ('2', '1'): 1500, ('2', '2'): 0, ('3', '1'): 900, ('3', '2'): 0}