【发布时间】:2017-01-21 17:35:39
【问题描述】:
教授的指示: 1. 使用 World Atlas 数据中按大洲划分的国家列表,将 countries.csv 文件加载到 pandas DataFrame 中,并将该数据集命名为国家。 2. 使用 Gapminder 上可用的数据,将人均收入(GDP/人均,PPP$ 通胀调整后)作为 pandas DataFrame 加载,并将该数据集命名为收入。 3. 将数据集转换为以年为行,以国家为列。加载时显示此数据集的头部。 4. 以图形方式显示世界各国在任何给定年份(例如 2000 年)的人均收入分布。什么样的情节最好?
在下面的代码中,我完成了其中一些任务,但我很难理解如何从 DataFrame 行获取数据。我希望能够从一行中获取数据然后绘制它。这似乎是一个微不足道的概念,但我已经研究了一段时间,需要帮助。
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
countries = pd.read_csv('2014_data/countries.csv')
countries.head(n=3)
income = pd.read_excel('indicator gapminder gdp_per_capita_ppp.xlsx')
income = income.T
def graph_per_year(year):
stryear = str(year)
dfList = income[stryear].tolist()
graph_per_year(1801)
【问题讨论】:
-
你能给我们展示一下
countries.head()和income.head()的输出吗?
标签: python pandas matplotlib dataframe data-science