【问题标题】:How to input a csv file into a Pygal Bar chart如何将 csv 文件输入到 Pygal 条形图中
【发布时间】:2023-04-09 13:47:01
【问题描述】:

我正在尝试创建一个条形图来展示来自欧洲不同国家/地区的 Spotify 溢价价格。我不知道如何导入 csv 文件来创建此图。这是我当前的代码

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 is my data 任何帮助都会得到帮助

【问题讨论】:

    标签: python csv graph pygal


    【解决方案1】:

    希望这可能会有所帮助:

    with open(filename, mode='r') as f:
    
    

    with open(filename, 'r') as f:
    
    

    with open(filename, 'rb') as f:
    
    

    或请参考此链接: https://realpython.com/python-csv/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多