第二课

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()
output_6_0.png
plt.boxplot(df.life)
plt.show()
output_7_0.png
plt.boxplot(df.gdp)
plt.show()
output_8_0.png
# 统计每个州的国家数
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()
output_12_0.png
plt.pie(conti_count, labels=conti, autopct='%1.1f%%')  # autopct 显示占比
plt.axis('equal')  # 调整坐标轴的比例
plt.show()
output_13_0.png
plt.plot(df.gdp, df.life)
plt.show()
output_14_0.png
plt.plot(df.gdp, df.life, 'g.')  # 'g.' 表示用绿色的点绘制
plt.show()
output_15_0.png
plt.scatter(df.gdp, df.life)
plt.show()
output_16_0.png
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.
output_17_1.png
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 

plt.scatter(df.gdp, df.life)

plt.xlabel('人均GDP(美元)')  # x轴名称
plt.ylabel('人均寿命(年)')   # y轴名称
plt.title('各国健康和经济水平关系(2015)')  # 图标题

plt.show()
output_18_0.png
plt.scatter(df.gdp, df.life)

plt.xscale('log')  # 对x轴采用对数刻度

plt.xlabel('人均GDP(美元)') 
plt.ylabel('人均寿命(年)')   
plt.title('各国健康和经济水平关系(2015)')  

plt.show()
output_19_0.png
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()
output_20_0.png
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()
output_21_0.png
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()
output_22_0.png
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()
output_23_0.png
#作业
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()
output_30_0.png
#显示人均GDP在2万美元以内的数据,没弄懂
#我也不清楚我写的这些代码是否正确,但是它读出来了。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,657评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,662评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,143评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,732评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,837评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,036评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,126评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,868评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,315评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,641评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,773评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,470评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,126评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,859评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,095评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,584评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,676评论 2 351

推荐阅读更多精彩内容