Learning pandas by Unknown

Learning pandas by Unknown

Author:Unknown
Language: eng
Format: mobi
Publisher: Packt Publishing


We can do some interesting things with this data. The example we will look at, determines which country has the lowest life expectancy for each year. To do this, we first need to pivot this data, so that the index is the country name and the year is the column. We will look at pivoting in more detail in later chapters, but for now, just know that the following reorganized the data into the country along the index and the year across the columns. Also, each value is the life expectancy for each country for that specific year:

In [53]: #le_data_all.pivot(index='country', columns='year') le_data = le_data_all.reset_index().pivot(index='country', columns='year') # examine pivoted data le_data.ix[:,0:3] Out[53]: SP.DYN.LE00.IN year 1980 1981 1982 country Afghanistan 41.233659 41.760634 42.335610 Albania 70.235976 70.454463 70.685122 Algeria 58.164024 59.486756 60.786341 American Samoa NaN NaN NaN Andorra NaN NaN NaN ... ... ... ... West Bank and Gaza NaN NaN NaN World 63.186868 63.494118 63.798264 Yemen, Rep. 50.559537 51.541341 52.492707 Zambia 51.148951 50.817707 50.350805 Zimbabwe 59.377610 59.944951 60.466171 [247 rows x 3 columns]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.