python绘制帕累托图
时间: 2023-10-17 16:37:38 浏览: 165
paretochart:python的帕累托图(类似于Matlab的图,但更加灵活)
要在Python中绘制帕累托图,可以按照以下步骤进行操作:
1. 首先,需要导入所需的模块:
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
```
2. 设置中文字体以确保在Matplotlib中显示中文:
```python
plt.rcParams["font.family"] = 'Arial Unicode MS'
```
3. 准备数据,将目标数据导入为Series对象:
```python
df = pd.read_csv('/Users/chenxiaogang/Desktop/data.csv',encoding='gb2312')
data = pd.Series(df['stastic'].values, index=df['city_name'])
```
4. 对数据进行排序,以便根据累计占比绘制帕累托图:
```python
data.sort_values(ascending=False, inplace=True)
```
5. 计算累计占比,并找到累计占比大于0.8的第一个索引名称:
```python
p = data.cumsum() / data.sum()
key = p[p > 0.8].index<span class="em">1</span>
#### 引用[.reference_title]
- *1* [学习笔记—使用python画帕累托分布图](https://blog.csdn.net/weixin_44896621/article/details/115030682)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文