description
The Python dictionary fromkeys() function is used to create a new dictionary, using the elements in the sequence seq as the keys of the dictionary, and the value is the initial value corresponding to all the keys of the dictionary.
fromkeys() method syntax
dict.fromkeys(seq, value)
parameter
- seq-a list of dictionary keys.
- value-optional parameter, set the value of the key sequence (seq).
return value
This method returns a new dictionary.
Core code
label is the character np array, num is the generated dictionary
num = dict.fromkeys(label)
import pandas as pd
job_info = pd.read_csv('job_info.csv',header=None,names=('公司','岗位','工作地点','工资','发布日期'),encoding = 'gbk')
label = job_info['岗位'].unique()
num = dict.fromkeys(label)
result: