Oxford - Data Analysis(1)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a19990412/article/details/81734760

Code - Python

Language: python 3.5

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_excel('data.xlsx')

df.set_index(["Year"], inplace=True)

X = [df.index[0], df.index[-1]]

popu = df["Population"]
gdp = df["GDP"]

xTicks = np.arange(min(X), max(X) + 1, 10)
if xTicks[-1] % 10 != 0:
    xtemp = xTicks.tolist()
    xtemp += [max(X)]
    xTicks = np.array(xtemp)
plt.xticks(xTicks)

average_gdp = gdp * 1000000 / popu
# print(average_gdp)
average_gdp.plot()
Y = [average_gdp.tolist()[-1], average_gdp.tolist()[-1]]

yTicks = np.arange(min(average_gdp), max(average_gdp) + 1, 2500)
if yTicks[-1] % 2500 != 0:
    ytemp = yTicks.tolist()
    ytemp += [max(average_gdp)]
    yTicks = np.array(ytemp)

plt.yticks(yTicks)

plt.plot(X, Y, 'r--')
plt.plot([df.index[-1], df.index[-1]], [average_gdp.tolist()[0], average_gdp.tolist()[-1]], 'r--')

plt.ylabel('GDP per capita / Pounds')
plt.title("GDP per capita Change in recent years(UK)")

plt.savefig('uk.png')
plt.show()

Data.xlsx detail

You can just copy it to an excel.
And the name of this excel file must be “data.xlsx”, then you can use the code above, otherwise you need to change the filename in the code.

Year    Population  GDP
1971    55928000    721255
1972    56096700    752283
1973    56222900    801247
1974    56235600    781509
1975    56225700    769950
1976    56216100    792356
1977    56189900    811714
1978    56178000    845821
1979    56240100    877467
1980    56329700    859674
1981    56357500    853046
1982    56290700    870197
1983    56315700    906936
1984    56409300    927580
1985    56554000    966495
1986    56683800    996691
1987    56804000    1049581
1988    56916400    1109907
1989    57076500    1138425
1990    57237500    1146756
1991    57438700    1134296
1992    57584500    1138538
1993    57713900    1167308
1994    57862100    1212600
1995    58024800    1242548
1996    58164400    1274093
1997    58314200    1325543
1998    58474900    1367136
1999    58684400    1411112
2000    58886100    1462818
2001    59113000    1500034
2002    59365700    1536903
2003    59636700    1588019
2004    59950400    1625567
2005    60413300    1675896
2006    60827100    1717055
2007    61319100    1757521
2008    61823800    1749216
2009    62260500    1675963
2010    62759500    1704364
2011    63285100    1729121
2012    63705000    1754736
2013    64105700    1790750
2014    64596800    1845444
2015    65110000    1888737
2016    65648100    1925299
2017    66040200    1959707

猜你喜欢

转载自blog.csdn.net/a19990412/article/details/81734760