python - 尝试用 Python 计算每十年的自杀人数
问题描述
我刚开始使用 Python,我正在尝试分析一些数据,目前的目标是一个图表,其中 Y 是总数,X 是年份。
我试过寻找有类似问题但没有真正成功的人。我试过阅读数组,甚至尝试过二维数组,但也没有成功。
for row in csv.reader:
if line_count == 0:
print(f'Comumn names are {", ".join(row)}')
line_count += 1
elif line_count <= 1000:
print(f"\t{row[0]} is the country and {row[1]} the year. The
sex was {row[2]}.")
t = f"\t{row[0]} is the country and {row[1]} the year. The
sex was {row[2]}."
if " male" in t:
males += 1
elif "female" in t:
females += 1
else:
none += 1
line_count += 1
else:
break
def stat():
if "198" in line_count(row[1]):
total[0] += 1
elif "199" in line_count(row[1]):
total[1] += 1
elif "200" in line_count(row[1]):
total[2] += 1
elif "201" in line_count(row[1]):
total[3] += 1
elif "202" in line_count(row[1]):
total[4] += 1
问题在于我的 matplotlib 正在使用 plt.plot()
我正在尝试围绕以下方面做一些事情:
plt.plot(years, currentDecadenDeaths)
years = [1980, 1990, 2000, 2010, 2020]
currentDecadenDeaths = [[years[0],[years[1],[years[2],[years[3],
[years[4], [total[0], total[1], total[2], total[3], total[4]]]
plt.plot(years, currentDecadenDeaths)
解决方案
years = [1980, 1990, 2000, 2010, 2020]
currentDecadenDeaths = [total[0], total[1], total[2], total[3], total[4]]
plt.plot(years, currentDecadenDeaths)
推荐阅读
- emacs - 为什么 Emacs local-set-key 不会覆盖模式挂钩中的全局设置键?
- php - 如何使用 PHP 编辑图像中的特定像素
- mysql - 完整性约束违规:1048 列 'temporary_address' 在可为空的字段中不能为空错误
- android - 小部件 onUpdate 调用一次
- javascript - JavaScript - 声明全局变量
- windows - 终端中的不可见文本与纱线
- javascript - 从 javascript 中已有的数组中创建新数组
- jquery - Angular - 如何在 angular component.ts 中定义 owl carousel 回调函数?
- c++ - 模板元编程 - g++ 吃掉它,clang 不吃
- reactjs - 为什么我在安装 REACT 时收到此错误?