import pandas as pd
import numpy as np #numpy是python的一种开源数字扩展。可用来存储和处理大型矩阵。
import matplotlib.pyplot as plt #matplotlib是python最著名的绘图库
%config InlineBackend.figure_format = 'retina' # 设置图像清晰度
data = pd.read_csv('WorldIndex.csv')
#读取文件
data.head()
#head为显示数据前五个
<style>
.dataframe thead tr:only-child th {
text-align: right;
}
.dataframe thead th {
text-align: left;
}
.dataframe tbody tr th {
vertical-align: top;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>Country</th>
<th>Continent</th>
<th>Life_expectancy</th>
<th>GDP_per_capita</th>
<th>Population</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>Algeria</td>
<td>Africa</td>
<td>75.042537</td>
<td>4132.760292</td>
<td>39871528.0</td>
</tr>
<tr>
<th>1</th>
<td>Angola</td>
<td>Africa</td>
<td>52.666098</td>
<td>3695.793748</td>
<td>27859305.0</td>
</tr>
<tr>
<th>2</th>
<td>Benin</td>
<td>Africa</td>
<td>59.720707</td>
<td>783.947091</td>
<td>10575952.0</td>
</tr>
<tr>
<th>3</th>
<td>Botswana</td>
<td>Africa</td>
<td>64.487415</td>
<td>6532.060501</td>
<td>2209197.0</td>
</tr>
<tr>
<th>4</th>
<td>Burundi</td>
<td>Africa</td>
<td>57.107049</td>
<td>303.681022</td>
<td>10199270.0</td>
</tr>
</tbody>
</table>
</div>
```python
data.info()
#统计信息
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 177 entries, 0 to 176
Data columns (total 5 columns):
Country 177 non-null object
Continent 177 non-null object
Life_expectancy 169 non-null float64
GDP_per_capita 169 non-null float64
Population 176 non-null float64
dtypes: float64(3), object(2)
memory usage: 7.0+ KB
# 删除包含缺失值的行
df = data.dropna()
df.info()
#dropna表示缺失的,空白的数据删除
<class 'pandas.core.frame.DataFrame'>
Int64Index: 164 entries, 0 to 175
Data columns (total 5 columns):
Country 164 non-null object
Continent 164 non-null object
Life_expectancy 164 non-null float64
GDP_per_capita 164 non-null float64
Population 164 non-null float64
dtypes: float64(3), object(2)
memory usage: 7.7+ KB
# 重新定义列名
df.columns = ['country', 'continent', 'life', 'gdp', 'popu']
plt.hist(df.life, bins=20, rwidth=0.6) # bins 设置区间数,rwidth设置柱子相对宽度
plt.show()
plt.boxplot(df.life)
plt.show()
plt.boxplot(df.gdp)
plt.show()
# 统计每个州的国家数
conti_count = df.continent.value_counts()
conti_count
Africa 48
Europe 41
Asia 36
North America 19
South America 11
Oceania 9
Name: continent, dtype: int64
# 获取各大州名称
conti = list(conti_count.index)
conti
['Africa', 'Europe', 'Asia', 'North America', 'South America', 'Oceania']
x = np.arange(len(conti))
x
array([0, 1, 2, 3, 4, 5])
# 条形图
plt.bar(x, conti_count)
# 设置横坐标
plt.xticks(x, conti, rotation=10) # rotation 旋转横坐标标签
plt.show()
plt.pie(conti_count, labels=conti, autopct='%1.1f%%') # autopct 显示占比
plt.axis('equal') # 调整坐标轴的比例
plt.show()
plt.plot(df.gdp, df.life)
plt.show()
plt.plot(df.gdp, df.life, 'g.') # 'g.' 表示用绿色的点绘制
plt.show()
plt.scatter(df.gdp, df.life)
plt.show()
pd.scatter_matrix(df)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: pandas.scatter_matrix is deprecated. Use pandas.plotting.scatter_matrix instead
"""Entry point for launching an IPython kernel.
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.scatter(df.gdp, df.life)
plt.xlabel('人均GDP(美元)') # x轴名称
plt.ylabel('人均寿命(年)') # y轴名称
plt.title('各国健康和经济水平关系(2015)') # 图标题
plt.show()
plt.scatter(df.gdp, df.life)
plt.xscale('log') # 对x轴采用对数刻度
plt.xlabel('人均GDP(美元)')
plt.ylabel('人均寿命(年)')
plt.title('各国健康和经济水平关系(2015)')
plt.show()
plt.scatter(df.gdp, df.life)
plt.xscale('log')
plt.xlabel('人均GDP(美元)')
plt.ylabel('人均寿命(年)')
plt.title('全球健康和收入水平关系(2015)')
tick_val = [1000,10000,100000]
tick_lab = ['1k','10k','100k']
plt.xticks(tick_val, tick_lab) # 重置x坐标刻度
plt.show()
size = df.popu / 1e6 * 2 # 数据点大小,正比于人口数
plt.scatter(x=df.gdp, y=df.life, s=size) # 参数s设置点的大小
plt.xscale('log')
plt.xlabel('人均GDP(美元)')
plt.ylabel('人均寿命(年)')
plt.title('全球健康和收入水平关系(2015)')
tick_val = [1000,10000,100000]
tick_lab = ['1k','10k','100k']
plt.xticks(tick_val, tick_lab)
plt.show()
map_dict = {
'Asia':'red',
'Europe':'green',
'Africa':'blue',
'North America':'yellow',
'South America':'yellow',
'Oceania':'black'
}
colors = df.continent.map(map_dict) # 将国家按所在州对于不同的颜色
size = df.popu / 1e6 * 2
plt.scatter(x=df.gdp, y=df.life, s=size, c=colors, alpha=0.5) # 参数c设置颜色,alpha设置透明度
plt.xscale('log')
plt.xlabel('人均GDP(美元)')
plt.ylabel('人均寿命(年)')
plt.title('全球健康和收入水平关系(2015)')
tick_val = [1000,10000,100000]
tick_lab = ['1k','10k','100k']
plt.xticks(tick_val, tick_lab)
plt.show()
map = {
'Asia':'red',
'Europe':'green',
'Africa':'blue',
'North America':'yellow',
'South America':'yellow',
'Oceania':'black'
}
colors = df.continent.map(map_dict)
size = df.popu / 1e6 * 2
plt.scatter(x=df.gdp, y=df.life, s=size, c=colors, alpha=0.5)
plt.xscale('log')
plt.xlabel('人均GDP(美元)')
plt.ylabel('人均寿命(年)')
plt.title('全球健康和收入水平关系(2015)')
tick_val = [1000,10000,100000]
tick_lab = ['1k','10k','100k']
plt.xticks(tick_val, tick_lab)
plt.text(1550, 73, 'India') # 在图中添加文本
plt.text(5700, 81, 'China')
plt.grid(True) # 添加网格
plt.show()
#作业
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'
data = pd.read_csv('WorldIndex.csv')
data
<div>
<style>
.dataframe thead tr:only-child th {
text-align: right;
}
.dataframe thead th {
text-align: left;
}
.dataframe tbody tr th {
vertical-align: top;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>Country</th>
<th>Continent</th>
<th>Life_expectancy</th>
<th>GDP_per_capita</th>
<th>Population</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>Algeria</td>
<td>Africa</td>
<td>75.042537</td>
<td>4132.760292</td>
<td>39871528.0</td>
</tr>
<tr>
<th>1</th>
<td>Angola</td>
<td>Africa</td>
<td>52.666098</td>
<td>3695.793748</td>
<td>27859305.0</td>
</tr>
<tr>
<th>2</th>
<td>Benin</td>
<td>Africa</td>
<td>59.720707</td>
<td>783.947091</td>
<td>10575952.0</td>
</tr>
<tr>
<th>3</th>
<td>Botswana</td>
<td>Africa</td>
<td>64.487415</td>
<td>6532.060501</td>
<td>2209197.0</td>
</tr>
<tr>
<th>4</th>
<td>Burundi</td>
<td>Africa</td>
<td>57.107049</td>
<td>303.681022</td>
<td>10199270.0</td>
</tr>
<tr>
<th>5</th>
<td>Cameroon</td>
<td>Africa</td>
<td>55.934390</td>
<td>1244.429421</td>
<td>22834522.0</td>
</tr>
<tr>
<th>6</th>
<td>Central African Republic</td>
<td>Africa</td>
<td>51.419122</td>
<td>348.381417</td>
<td>4546100.0</td>
</tr>
<tr>
<th>7</th>
<td>Chad</td>
<td>Africa</td>
<td>51.873317</td>
<td>777.248705</td>
<td>14009413.0</td>
</tr>
<tr>
<th>8</th>
<td>Comoros</td>
<td>Africa</td>
<td>63.554024</td>
<td>727.646387</td>
<td>777424.0</td>
</tr>
<tr>
<th>9</th>
<td>Congo</td>
<td>Africa</td>
<td>62.867659</td>
<td>1712.121131</td>
<td>4995648.0</td>
</tr>
<tr>
<th>10</th>
<td>Djibouti</td>
<td>Africa</td>
<td>62.285659</td>
<td>1862.167274</td>
<td>927414.0</td>
</tr>
<tr>
<th>11</th>
<td>Egypt</td>
<td>Africa</td>
<td>71.316951</td>
<td>3547.713012</td>
<td>93778172.0</td>
</tr>
<tr>
<th>12</th>
<td>Equatorial Guinea</td>
<td>Africa</td>
<td>57.963415</td>
<td>10347.312570</td>
<td>1175389.0</td>
</tr>
<tr>
<th>13</th>
<td>Eritrea</td>
<td>Africa</td>
<td>64.100902</td>
<td>NaN</td>
<td>NaN</td>
</tr>
<tr>
<th>14</th>
<td>Ethiopia</td>
<td>Africa</td>
<td>64.578049</td>
<td>645.463763</td>
<td>99873033.0</td>
</tr>
<tr>
<th>15</th>
<td>Gabon</td>
<td>Africa</td>
<td>64.890341</td>
<td>7388.984144</td>
<td>1930175.0</td>
</tr>
<tr>
<th>16</th>
<td>Gambia</td>
<td>Africa</td>
<td>60.467683</td>
<td>474.716559</td>
<td>1977590.0</td>
</tr>
<tr>
<th>17</th>
<td>Ghana</td>
<td>Africa</td>
<td>61.491732</td>
<td>1361.113905</td>
<td>27582821.0</td>
</tr>
<tr>
<th>18</th>
<td>Guinea</td>
<td>Africa</td>
<td>59.193439</td>
<td>554.040877</td>
<td>12091533.0</td>
</tr>
<tr>
<th>19</th>
<td>Guinea-Bissau</td>
<td>Africa</td>
<td>55.467317</td>
<td>596.871719</td>
<td>1770526.0</td>
</tr>
<tr>
<th>20</th>
<td>Kenya</td>
<td>Africa</td>
<td>62.133732</td>
<td>1349.970144</td>
<td>47236259.0</td>
</tr>
<tr>
<th>21</th>
<td>Lesotho</td>
<td>Africa</td>
<td>49.961220</td>
<td>1073.828093</td>
<td>2174645.0</td>
</tr>
<tr>
<th>22</th>
<td>Liberia</td>
<td>Africa</td>
<td>61.160951</td>
<td>452.038072</td>
<td>4499621.0</td>
</tr>
<tr>
<th>23</th>
<td>Libya</td>
<td>Africa</td>
<td>71.826317</td>
<td>NaN</td>
<td>6234955.0</td>
</tr>
<tr>
<th>24</th>
<td>Madagascar</td>
<td>Africa</td>
<td>65.482780</td>
<td>401.857595</td>
<td>24234088.0</td>
</tr>
<tr>
<th>25</th>
<td>Malawi</td>
<td>Africa</td>
<td>63.796854</td>
<td>362.657544</td>
<td>17573607.0</td>
</tr>
<tr>
<th>26</th>
<td>Mali</td>
<td>Africa</td>
<td>58.457220</td>
<td>729.720534</td>
<td>17467905.0</td>
</tr>
<tr>
<th>27</th>
<td>Mauritania</td>
<td>Africa</td>
<td>63.202829</td>
<td>1158.256469</td>
<td>4182341.0</td>
</tr>
<tr>
<th>28</th>
<td>Mauritius</td>
<td>Africa</td>
<td>74.353171</td>
<td>9252.110724</td>
<td>1262605.0</td>
</tr>
<tr>
<th>29</th>
<td>Morocco</td>
<td>Africa</td>
<td>74.289317</td>
<td>2847.285569</td>
<td>34803322.0</td>
</tr>
<tr>
<th>...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<th>147</th>
<td>Nicaragua</td>
<td>North America</td>
<td>75.098122</td>
<td>2095.966488</td>
<td>6082035.0</td>
</tr>
<tr>
<th>148</th>
<td>Panama</td>
<td>North America</td>
<td>77.767293</td>
<td>13134.043670</td>
<td>3969249.0</td>
</tr>
<tr>
<th>149</th>
<td>Trinidad and Tobago</td>
<td>North America</td>
<td>70.557707</td>
<td>17321.833730</td>
<td>1360092.0</td>
</tr>
<tr>
<th>150</th>
<td>United States</td>
<td>North America</td>
<td>78.741463</td>
<td>56207.036750</td>
<td>320896618.0</td>
</tr>
<tr>
<th>151</th>
<td>Australia</td>
<td>Oceania</td>
<td>82.451220</td>
<td>56554.038760</td>
<td>23789338.0</td>
</tr>
<tr>
<th>152</th>
<td>Fiji</td>
<td>Oceania</td>
<td>70.256268</td>
<td>4921.896209</td>
<td>892149.0</td>
</tr>
<tr>
<th>153</th>
<td>Kiribati</td>
<td>Oceania</td>
<td>66.147854</td>
<td>1424.483611</td>
<td>112407.0</td>
</tr>
<tr>
<th>154</th>
<td>Marshall Islands</td>
<td>Oceania</td>
<td>NaN</td>
<td>3385.904065</td>
<td>52994.0</td>
</tr>
<tr>
<th>155</th>
<td>Micronesia</td>
<td>Oceania</td>
<td>69.234244</td>
<td>3016.011223</td>
<td>104433.0</td>
</tr>
<tr>
<th>156</th>
<td>Nauru</td>
<td>Oceania</td>
<td>NaN</td>
<td>8052.888385</td>
<td>12475.0</td>
</tr>
<tr>
<th>157</th>
<td>New Zealand</td>
<td>Oceania</td>
<td>81.456829</td>
<td>38201.890370</td>
<td>4595700.0</td>
</tr>
<tr>
<th>158</th>
<td>Palau</td>
<td>Oceania</td>
<td>NaN</td>
<td>13500.563700</td>
<td>21288.0</td>
</tr>
<tr>
<th>159</th>
<td>Papua New Guinea</td>
<td>Oceania</td>
<td>62.776683</td>
<td>NaN</td>
<td>7919825.0</td>
</tr>
<tr>
<th>160</th>
<td>Samoa</td>
<td>Oceania</td>
<td>73.764878</td>
<td>4149.363444</td>
<td>193759.0</td>
</tr>
<tr>
<th>161</th>
<td>Solomon Islands</td>
<td>Oceania</td>
<td>68.146244</td>
<td>1922.041388</td>
<td>587482.0</td>
</tr>
<tr>
<th>162</th>
<td>Tonga</td>
<td>Oceania</td>
<td>72.944049</td>
<td>4093.775387</td>
<td>106364.0</td>
</tr>
<tr>
<th>163</th>
<td>Tuvalu</td>
<td>Oceania</td>
<td>NaN</td>
<td>2970.027974</td>
<td>11001.0</td>
</tr>
<tr>
<th>164</th>
<td>Vanuatu</td>
<td>Oceania</td>
<td>72.157366</td>
<td>2805.834140</td>
<td>264603.0</td>
</tr>
<tr>
<th>165</th>
<td>Argentina</td>
<td>South America</td>
<td>76.334220</td>
<td>13467.102360</td>
<td>43417765.0</td>
</tr>
<tr>
<th>166</th>
<td>Bolivia</td>
<td>South America</td>
<td>68.739610</td>
<td>3077.026199</td>
<td>10724705.0</td>
</tr>
<tr>
<th>167</th>
<td>Brazil</td>
<td>South America</td>
<td>74.675878</td>
<td>8757.206202</td>
<td>205962108.0</td>
</tr>
<tr>
<th>168</th>
<td>Chile</td>
<td>South America</td>
<td>81.787561</td>
<td>13653.226730</td>
<td>17762681.0</td>
</tr>
<tr>
<th>169</th>
<td>Colombia</td>
<td>South America</td>
<td>74.182024</td>
<td>6044.525556</td>
<td>48228697.0</td>
</tr>
<tr>
<th>170</th>
<td>Ecuador</td>
<td>South America</td>
<td>76.102927</td>
<td>6205.062224</td>
<td>16144368.0</td>
</tr>
<tr>
<th>171</th>
<td>Guyana</td>
<td>South America</td>
<td>66.507512</td>
<td>4136.689919</td>
<td>768514.0</td>
</tr>
<tr>
<th>172</th>
<td>Paraguay</td>
<td>South America</td>
<td>73.025634</td>
<td>4109.367724</td>
<td>6639119.0</td>
</tr>
<tr>
<th>173</th>
<td>Peru</td>
<td>South America</td>
<td>74.780732</td>
<td>6030.343259</td>
<td>31376671.0</td>
</tr>
<tr>
<th>174</th>
<td>Suriname</td>
<td>South America</td>
<td>71.294171</td>
<td>8818.982566</td>
<td>553208.0</td>
</tr>
<tr>
<th>175</th>
<td>Uruguay</td>
<td>South America</td>
<td>77.138220</td>
<td>15524.842470</td>
<td>3431552.0</td>
</tr>
<tr>
<th>176</th>
<td>Venezuela</td>
<td>South America</td>
<td>74.409610</td>
<td>NaN</td>
<td>31155134.0</td>
</tr>
</tbody>
</table>
<p>177 rows × 5 columns</p>
</div>
df = data.dropna()
df
<div>
<style>
.dataframe thead tr:only-child th {
text-align: right;
}
.dataframe thead th {
text-align: left;
}
.dataframe tbody tr th {
vertical-align: top;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>Country</th>
<th>Continent</th>
<th>Life_expectancy</th>
<th>GDP_per_capita</th>
<th>Population</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>Algeria</td>
<td>Africa</td>
<td>75.042537</td>
<td>4132.760292</td>
<td>39871528.0</td>
</tr>
<tr>
<th>1</th>
<td>Angola</td>
<td>Africa</td>
<td>52.666098</td>
<td>3695.793748</td>
<td>27859305.0</td>
</tr>
<tr>
<th>2</th>
<td>Benin</td>
<td>Africa</td>
<td>59.720707</td>
<td>783.947091</td>
<td>10575952.0</td>
</tr>
<tr>
<th>3</th>
<td>Botswana</td>
<td>Africa</td>
<td>64.487415</td>
<td>6532.060501</td>
<td>2209197.0</td>
</tr>
<tr>
<th>4</th>
<td>Burundi</td>
<td>Africa</td>
<td>57.107049</td>
<td>303.681022</td>
<td>10199270.0</td>
</tr>
<tr>
<th>5</th>
<td>Cameroon</td>
<td>Africa</td>
<td>55.934390</td>
<td>1244.429421</td>
<td>22834522.0</td>
</tr>
<tr>
<th>6</th>
<td>Central African Republic</td>
<td>Africa</td>
<td>51.419122</td>
<td>348.381417</td>
<td>4546100.0</td>
</tr>
<tr>
<th>7</th>
<td>Chad</td>
<td>Africa</td>
<td>51.873317</td>
<td>777.248705</td>
<td>14009413.0</td>
</tr>
<tr>
<th>8</th>
<td>Comoros</td>
<td>Africa</td>
<td>63.554024</td>
<td>727.646387</td>
<td>777424.0</td>
</tr>
<tr>
<th>9</th>
<td>Congo</td>
<td>Africa</td>
<td>62.867659</td>
<td>1712.121131</td>
<td>4995648.0</td>
</tr>
<tr>
<th>10</th>
<td>Djibouti</td>
<td>Africa</td>
<td>62.285659</td>
<td>1862.167274</td>
<td>927414.0</td>
</tr>
<tr>
<th>11</th>
<td>Egypt</td>
<td>Africa</td>
<td>71.316951</td>
<td>3547.713012</td>
<td>93778172.0</td>
</tr>
<tr>
<th>12</th>
<td>Equatorial Guinea</td>
<td>Africa</td>
<td>57.963415</td>
<td>10347.312570</td>
<td>1175389.0</td>
</tr>
<tr>
<th>14</th>
<td>Ethiopia</td>
<td>Africa</td>
<td>64.578049</td>
<td>645.463763</td>
<td>99873033.0</td>
</tr>
<tr>
<th>15</th>
<td>Gabon</td>
<td>Africa</td>
<td>64.890341</td>
<td>7388.984144</td>
<td>1930175.0</td>
</tr>
<tr>
<th>16</th>
<td>Gambia</td>
<td>Africa</td>
<td>60.467683</td>
<td>474.716559</td>
<td>1977590.0</td>
</tr>
<tr>
<th>17</th>
<td>Ghana</td>
<td>Africa</td>
<td>61.491732</td>
<td>1361.113905</td>
<td>27582821.0</td>
</tr>
<tr>
<th>18</th>
<td>Guinea</td>
<td>Africa</td>
<td>59.193439</td>
<td>554.040877</td>
<td>12091533.0</td>
</tr>
<tr>
<th>19</th>
<td>Guinea-Bissau</td>
<td>Africa</td>
<td>55.467317</td>
<td>596.871719</td>
<td>1770526.0</td>
</tr>
<tr>
<th>20</th>
<td>Kenya</td>
<td>Africa</td>
<td>62.133732</td>
<td>1349.970144</td>
<td>47236259.0</td>
</tr>
<tr>
<th>21</th>
<td>Lesotho</td>
<td>Africa</td>
<td>49.961220</td>
<td>1073.828093</td>
<td>2174645.0</td>
</tr>
<tr>
<th>22</th>
<td>Liberia</td>
<td>Africa</td>
<td>61.160951</td>
<td>452.038072</td>
<td>4499621.0</td>
</tr>
<tr>
<th>24</th>
<td>Madagascar</td>
<td>Africa</td>
<td>65.482780</td>
<td>401.857595</td>
<td>24234088.0</td>
</tr>
<tr>
<th>25</th>
<td>Malawi</td>
<td>Africa</td>
<td>63.796854</td>
<td>362.657544</td>
<td>17573607.0</td>
</tr>
<tr>
<th>26</th>
<td>Mali</td>
<td>Africa</td>
<td>58.457220</td>
<td>729.720534</td>
<td>17467905.0</td>
</tr>
<tr>
<th>27</th>
<td>Mauritania</td>
<td>Africa</td>
<td>63.202829</td>
<td>1158.256469</td>
<td>4182341.0</td>
</tr>
<tr>
<th>28</th>
<td>Mauritius</td>
<td>Africa</td>
<td>74.353171</td>
<td>9252.110724</td>
<td>1262605.0</td>
</tr>
<tr>
<th>29</th>
<td>Morocco</td>
<td>Africa</td>
<td>74.289317</td>
<td>2847.285569</td>
<td>34803322.0</td>
</tr>
<tr>
<th>30</th>
<td>Mozambique</td>
<td>Africa</td>
<td>55.371244</td>
<td>528.312560</td>
<td>28010691.0</td>
</tr>
<tr>
<th>31</th>
<td>Namibia</td>
<td>Africa</td>
<td>64.915439</td>
<td>4737.669906</td>
<td>2425561.0</td>
</tr>
<tr>
<th>...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<th>141</th>
<td>Grenada</td>
<td>North America</td>
<td>73.523000</td>
<td>9212.192824</td>
<td>106823.0</td>
</tr>
<tr>
<th>142</th>
<td>Guatemala</td>
<td>North America</td>
<td>71.956488</td>
<td>3923.573344</td>
<td>16252429.0</td>
</tr>
<tr>
<th>143</th>
<td>Haiti</td>
<td>North America</td>
<td>63.073756</td>
<td>814.546395</td>
<td>10711061.0</td>
</tr>
<tr>
<th>144</th>
<td>Honduras</td>
<td>North America</td>
<td>73.333122</td>
<td>2326.158506</td>
<td>8960829.0</td>
</tr>
<tr>
<th>145</th>
<td>Jamaica</td>
<td>North America</td>
<td>75.798171</td>
<td>4965.989857</td>
<td>2871934.0</td>
</tr>
<tr>
<th>146</th>
<td>Mexico</td>
<td>North America</td>
<td>76.920683</td>
<td>9143.128494</td>
<td>125890949.0</td>
</tr>
<tr>
<th>147</th>
<td>Nicaragua</td>
<td>North America</td>
<td>75.098122</td>
<td>2095.966488</td>
<td>6082035.0</td>
</tr>
<tr>
<th>148</th>
<td>Panama</td>
<td>North America</td>
<td>77.767293</td>
<td>13134.043670</td>
<td>3969249.0</td>
</tr>
<tr>
<th>149</th>
<td>Trinidad and Tobago</td>
<td>North America</td>
<td>70.557707</td>
<td>17321.833730</td>
<td>1360092.0</td>
</tr>
<tr>
<th>150</th>
<td>United States</td>
<td>North America</td>
<td>78.741463</td>
<td>56207.036750</td>
<td>320896618.0</td>
</tr>
<tr>
<th>151</th>
<td>Australia</td>
<td>Oceania</td>
<td>82.451220</td>
<td>56554.038760</td>
<td>23789338.0</td>
</tr>
<tr>
<th>152</th>
<td>Fiji</td>
<td>Oceania</td>
<td>70.256268</td>
<td>4921.896209</td>
<td>892149.0</td>
</tr>
<tr>
<th>153</th>
<td>Kiribati</td>
<td>Oceania</td>
<td>66.147854</td>
<td>1424.483611</td>
<td>112407.0</td>
</tr>
<tr>
<th>155</th>
<td>Micronesia</td>
<td>Oceania</td>
<td>69.234244</td>
<td>3016.011223</td>
<td>104433.0</td>
</tr>
<tr>
<th>157</th>
<td>New Zealand</td>
<td>Oceania</td>
<td>81.456829</td>
<td>38201.890370</td>
<td>4595700.0</td>
</tr>
<tr>
<th>160</th>
<td>Samoa</td>
<td>Oceania</td>
<td>73.764878</td>
<td>4149.363444</td>
<td>193759.0</td>
</tr>
<tr>
<th>161</th>
<td>Solomon Islands</td>
<td>Oceania</td>
<td>68.146244</td>
<td>1922.041388</td>
<td>587482.0</td>
</tr>
<tr>
<th>162</th>
<td>Tonga</td>
<td>Oceania</td>
<td>72.944049</td>
<td>4093.775387</td>
<td>106364.0</td>
</tr>
<tr>
<th>164</th>
<td>Vanuatu</td>
<td>Oceania</td>
<td>72.157366</td>
<td>2805.834140</td>
<td>264603.0</td>
</tr>
<tr>
<th>165</th>
<td>Argentina</td>
<td>South America</td>
<td>76.334220</td>
<td>13467.102360</td>
<td>43417765.0</td>
</tr>
<tr>
<th>166</th>
<td>Bolivia</td>
<td>South America</td>
<td>68.739610</td>
<td>3077.026199</td>
<td>10724705.0</td>
</tr>
<tr>
<th>167</th>
<td>Brazil</td>
<td>South America</td>
<td>74.675878</td>
<td>8757.206202</td>
<td>205962108.0</td>
</tr>
<tr>
<th>168</th>
<td>Chile</td>
<td>South America</td>
<td>81.787561</td>
<td>13653.226730</td>
<td>17762681.0</td>
</tr>
<tr>
<th>169</th>
<td>Colombia</td>
<td>South America</td>
<td>74.182024</td>
<td>6044.525556</td>
<td>48228697.0</td>
</tr>
<tr>
<th>170</th>
<td>Ecuador</td>
<td>South America</td>
<td>76.102927</td>
<td>6205.062224</td>
<td>16144368.0</td>
</tr>
<tr>
<th>171</th>
<td>Guyana</td>
<td>South America</td>
<td>66.507512</td>
<td>4136.689919</td>
<td>768514.0</td>
</tr>
<tr>
<th>172</th>
<td>Paraguay</td>
<td>South America</td>
<td>73.025634</td>
<td>4109.367724</td>
<td>6639119.0</td>
</tr>
<tr>
<th>173</th>
<td>Peru</td>
<td>South America</td>
<td>74.780732</td>
<td>6030.343259</td>
<td>31376671.0</td>
</tr>
<tr>
<th>174</th>
<td>Suriname</td>
<td>South America</td>
<td>71.294171</td>
<td>8818.982566</td>
<td>553208.0</td>
</tr>
<tr>
<th>175</th>
<td>Uruguay</td>
<td>South America</td>
<td>77.138220</td>
<td>15524.842470</td>
<td>3431552.0</td>
</tr>
</tbody>
</table>
<p>164 rows × 5 columns</p>
</div>
df.columns = ['country', 'continent', 'life', 'gdp', 'popu']
plt.hist(df.gdp, bins=30, rwidth=0.9)
plt.xlabel('77')
plt.ylabel('88')
plt.title('人均GDP')
map_dict ={'Gdp':'green'}
colors = df.gdp.map(map_dict)
plt.show()
#显示人均GDP在2万美元以内的数据,没弄懂
#我也不清楚我写的这些代码是否正确,但是它读出来了。