【问题标题】:Python - Read and plot data from a .csvPython - 从 .csv 读取和绘制数据
【发布时间】:2015-01-30 05:32:00
【问题描述】:

我有一个 .csv,其中包含不同国家/地区的 GDP 数据。我想阅读该文件并在 .csv 文件中仅绘制少数几个国家的数据。到目前为止,我有:

data = np.genfromtxt('The_data.csv', dtype=str, delimiter=',', names=None, usecols=np.arange(0,17))

我认为这可以让我读取数据。如何使用 matplotlib 生成多年来的 GDP 变化图,但仅限于某些国家/地区?

【问题讨论】:

  • 认为它让您读取数据?你试过了吗?在那种情况下,data 看起来像什么?

标签: python csv numpy matplotlib graphing


【解决方案1】:
with open(The_data.csv) as f:
    content = f.readlines()
    My_list=[]
    for line in content:         
        My_list.add(line.split(';') )

或使用 CSV 模块https://docs.python.org/2/library/csv.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-26
    • 2019-11-01
    • 1970-01-01
    • 2021-02-10
    • 2023-02-09
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    相关资源
    最近更新 更多