用pandas将下面数据画一张统计图表日期/项目(A厂) 进水 COD 氨氮 总磷 总氮 2021.1.1 149 20.1 3.54 30.7 2021.1.2 164 10.1 0.65 20.1 2021.1.3 86 37.1 1.92 44.1 2021.1.4 164 16.4 1.44 21.5 2021.1.5 146 10.9 0.84 18.4 2021.1.6 136 18.7 1.59 29.7 2021.1.7 93 17.2 1.15 23.5 2021.1.8 96 17.1 1.61 24.2 2021.1.9 90 18.5 1.42 26.9 2021.1.10 134 23.8 2.46 31.7 2021.1.11 141 17.7 2.50 28.3 2021.1.12 15.6 1.48 2021.1.13 11.0 1.04 2021.1.14 19.5 3.55 24.0 2021.1.15 138 18.5 1.60 26.9 2021.1.16 138 15.2 1.82 27.8 2021.1.17 161 16.5 2.60 20.5 2021.1.18 16.3 2.10 27.9 2021.1.19 17.3 1.54 31.8 2021.1.20 29.5 3.54 37.8 2021.1.21 20.7 2.67 24.9 2021.1.22 19.5 3.25 29.3 2021.1.23 18.9 2.12 2021.1.24 12.0 2.38 23.4 2021.1.25 23.9 2.34 23.5 2021.1.26 11.7 1.51 12.4 2021.1.27 114 10.6 1.58 27.9 2021.1.28 107 11.1 1.31 19.3 2021.1.29 121 14.2 1.66 17.6 2021.1.30 10.6 1.26 19.5 2021.1.31 12.5 1.71 15.4
时间: 2023-08-06 11:06:01 浏览: 212
首先,需要将数据转换成pandas的DataFrame格式,代码如下:
```python
import pandas as pd
data = {'日期/项目(A厂)': ['2021.1.1', '2021.1.2', '2021.1.3', '2021.1.4', '2021.1.5', '2021.1.6', '2021.1.7', '2021.1.8', '2021.1.9', '2021.1.10', '2021.1.11', '2021.1.12', '2021.1.13', '2021.1.14', '2021.1.15', '2021.1.16', '2021.1.17', '2021.1.18', '2021.1.19', '2021.1.20', '2021.1.21', '2021.1.22', '2021.1.23', '2021.1.24', '2021.1.25', '2021.1.26', '2021.1.27', '2021.1.28', '2021.1.29', '2021.1.30', '2021.1.31'],
'进水': [149, 164, 86, 164, 146, 136, 93, 96, 90, 134, 141, None, None, None, 138, 138, 161, None, None, None, None, None, None, None, None, None, 114, 107, 121, None, None],
'COD': [20.1, 10.1, 37.1, 16.4, 10.9, 18.7, 17.2, 17.1, 18.5, 23.8, 17.7, 15.6, 11.0, 19.5, 18.5, 15.2, 16.5, 16.3, 17.3, 29.5, 20.7, 19.5, 18.9, 12.0, 23.9, 11.7, 10.6, 11.1, 14.2, 10.6, 12.5],
'氨氮': [3.54, 0.65, 1.92, 1.44, 0.84, 1.59, 1.15, 1.61, 1.42, 2.46, 2.50, 1.48, 1.04, 3.55, 1.60, 1.82, 2.60, 2.10, 1.54, 3.54, 2.67, 3.25, 2.12, 2.38, 2.34, 1.51, 1.58, 1.31, 1.66, 1.26, 1.71],
'总磷': [30.7, 20.1, 44.1, 21.5, 18.4, 29.7, 23.5, 24.2, 26.9, 31.7, 28.3, None, None, 24.0, 26.9, 27.8, 20.5, 27.9, 31.8, 37.8, 24.9, 29.3, None, 23.4, 23.5, 12.4, 27.9, 19.3, 17.6, 19.5, 15.4]}
df = pd.DataFrame(data)
```
接下来,我们可以使用matplotlib库进行数据可视化,这里我选择绘制折线图。代码如下:
```python
import matplotlib.pyplot as plt
# 设置图形大小
plt.figure(figsize=(10, 6))
# 绘制折线图
plt.plot(df['日期/项目(A厂)'], df['进水'], label='进水')
plt.plot(df['日期/项目(A厂)'], df['COD'], label='COD')
plt.plot(df['日期/项目(A厂)'], df['氨氮'], label='氨氮')
plt.plot(df['日期/项目(A厂)'], df['总磷'], label='总磷')
# 添加标题和标签
plt.title('A厂水质监测', fontsize=16)
plt.xlabel('日期', fontsize=12)
plt.ylabel('含量', fontsize=12)
# 添加图例
plt.legend()
# 显示图形
plt.show()
```
运行上述代码,即可得到一张含有4条曲线的折线图,用于展示A厂水质监测数据的趋势。
阅读全文