作者:cgy梦回秦都 | 来源:互联网 | 2023-10-12 19:58
importpandasaspddatapd.DataFrame([[‘a’,1],[‘b’,2]],columns[‘key’,‘value’])dict1dict(zip(da
import pandas as pd
data = pd.DataFrame([[‘a’,1],[‘b’,2]], columns=[‘key’,‘value’])
dict1 = dict(zip(data[‘key’],data[‘value’]))
a_dict = {‘a’: 1, ‘b’: 2, ‘c’: 3}
{value:key for key, value in a_dict.items()}
{1: ‘a’, 2: ‘b’, 3: ‘c’}
dic = {‘a’:1, ‘b’:2, ‘c’:3}
dic_new = dict(zip(dic.values(), dic.keys()))
print(dic_new)
{1: ‘a’, 2: ‘b’, 3: ‘c’}
dic = {‘a’:1, ‘b’:2, ‘c’:3}
dic_new = {}
for key, val in dic.items():
dic_new[val] = key
print(dic_new)
{1: ‘a’, 2: ‘b’, 3: ‘c’}
dic_new = dict([val, key] for key, val in dic.items())
print(dic_new)
{1: ‘a’, 2: ‘b’, 3: ‘c’}