[英]How to input a csv file into a Pygal Bar chart
I am trying to create a barchart showing off the price of spotify premium from different countries around europe.我正在尝试创建一个条形图,展示来自欧洲不同国家/地区的 spotify 溢价价格。 I do not know how to import a csv file to create this graph.
我不知道如何导入 csv 文件来创建此图。 this is my current code
这是我当前的代码
import pygal as pg
import csv
filename = 'premiumusersEurope.csv'
with open(filename) as f:
reader = csv.reader(f)
#print(list(reader))
pg_bar = pg.Bar()
for row in reader:
x.append(int(row[0]))
y.append(int(row[1]))
pg_bar.render_to_file("simple.svg")
This code is not working, and i cannot find out why.此代码不起作用,我无法找出原因。
This is my data any help will be appriciated这是我的数据,任何帮助都会得到帮助
Hope this may help:希望这可能会有所帮助:
with open(filename, mode='r') as f:
or或者
with open(filename, 'r') as f:
or或者
with open(filename, 'rb') as f:
or please refer this link: https://realpython.com/python-csv/或者请参考这个链接: https://realpython.com/python-csv/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.