我刚开始使用Python并试图分析一些数据,目前的目标是创建一个图表,其中Y为总数,X为年份。
我试图找到有类似问题但没有真正成功的人。我尝试读取数组,甚至尝试使用2D数组,但也没有成功。
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)
答案 0 :(得分:2)
years = [1980, 1990, 2000, 2010, 2020]
currentDecadenDeaths = [total[0], total[1], total[2], total[3], total[4]]
plt.plot(years, currentDecadenDeaths)