In pandas, change the English name of a column to the corresponding Chinese (using the dictionary)

For example, the English location under the district attribute in a pandas list is rewritten into the corresponding Chinese location name, which is convenient for drawing.

#构造一个更改对应的字典
dist_dict = {'longgang':'龙岗','longhua':'龙华','baoan':'宝安','nanshan':'南山','futian':'福田','luohu':'罗湖','pingshan':'坪山','guangming':'光明','yantian':'盐田','dapengxinqu':'大鹏新区'}
#利用匿名函数进行依次更改
data['district']=data['district'].apply(lambda x:dist_dict[x])
print(data)

Output result:
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_39920026/article/details/108493738