pandas - 为条形图图例熊猫中的整数分配标签
问题描述
我想将“单身”分配给 0,将“已婚”分配给 1,并将其显示在条形图中
这是我写的代码:
ds["Marital_Status"].value_counts().plot(kind='bar',color=['green', 'cyan'], rot=0)
plt.title('买家婚姻状况')
解决方案
使用Series.map
:
( ds["Marital_Status"].map({0:'Single',1:'Married'})
.value_counts()
.plot(kind='bar',color=['green', 'cyan'], rot=0) )
# if is string type
#ds["Marital_Status"].map({'0':'Single','1':'Married'})
推荐阅读
- facebook - 我无法通过 API 创建 Facebook 相似受众?
- augmented-reality - 如何在 RealityKit 中的网格环境上投射阴影?
- javascript - TypeScript如何在数组上的Reduce函数上设置累积值和初始值的类型
- android-security - Android 意图重定向漏洞
- javascript - 访问 javascript 对象中的嵌套 JSON 键,其中键是动态的
- reactjs - ReactJs + TypeScript中的类型中不存在元素
- google-apps-script - 使用 Apps 脚本搜索超过 10 分钟的邮件
- c++ - 在堆上“分解” c++ 数组是否安全?
- php - 将所有字符编码为实体
- zabbix - Zabbix 用户自定义参数,带 PSK 加密