'How can i make each key in a dictionary a string and make the value of that key a Python list
I am trying to convert a dictionary key to a string and make the values a list
this is where i am and i don't know what to do next
dict_from_csv = pd.read_csv('Emissions.csv', header=None, index_col=0, squeeze=True).to_dict()
keys = list(dict_from_csv.keys())
values = list(dict_from_csv.values())
keys
values
Solution 1:[1]
Do you want a unique string to represent all the keys? If yes, you can do this:
keys = " ".join(list(dict_from_csv.keys()))
And, Do you like a single list with all values? If yes, you can do this:
values = [val for key in df for val in dict_from_csv[key].values()]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ítalo De Pontes Oliveira |
