教授給出的指令: 1.使用來自World Atlas數據的continent國家列表,將countries.csv文件加載到pandas DataFrame中,並將該數據集命名爲國家。 2.使用Gapminder上提供的數據,將每人的收入(GDP /人均,PPP $通貨膨脹調整後)作爲熊貓數據框載入,並將此數據集命名爲收入。 3.將數據集轉換爲以行和國家作爲列的年份。加載時顯示該數據集的頭部。 4.以圖形方式顯示任何特定年份(例如2000年)世界各國人均收入分佈情況。什麼樣的情節最好?從Pandas中的一行中獲取數據
在下面的代碼中,我完成了其中一些任務,但我很難理解如何從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)
http://pandas.pydata.org/pandas-docs/stable/indexing.html –
您可以向我們展示'countries.head()'和'income.head()'的輸出以供說明嗎? – tipanverella