How to input a csv file into a Pygal Bar chart

280 views Asked by At

I am trying to create a barchart showing off the price of spotify premium from different countries around europe. I do not know how to import a csv file to create this graph. 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

1

There are 1 answers

0
TechCure On

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/