python大数据分析|第5课 数据可视化分析

1.调用数据

df=pd.read_csv('WorldIndex.csv')
df.head()
WorldIndex

2.查看数据

df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 164 entries, 0 to 163
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 int64
dtypes: float64(2), int64(1), object(2)
memory usage: 5.2+ KB

看数据表格有多少行和列:
df.shape
(164,5)
查看有哪些大陆:
df.continent.unique()
array(['Africa', 'Asia', 'Europe', 'North America', 'Oceania', 'South America'], dtype=object)
这些大陆各有几个国家:
df.continent.value_counts()

Africa           48
Europe           41
Asia             36
North America    19
South America    11
Oceania           9
Name: Continent, dtype: int64

3.将数据进行可视化操作:

df.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita")

散点图

用不同的颜色表示不同大洲的国家,并将图表放大:

Africa=df[df.Continent=='Africa']
Asia=df[df.Continent=='Asia']
Europe=df[df.Continent=='Europe']
North_America=df[df.Continent=='North America']
Oceania=df[df.Continent=='Oceania']
South_America=df[df.Continent=='South America']

ax=Africa.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Red',label='Africa',figsize=(10,6))
Asia.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Green',ax=ax,label='Asia')
Europe.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Orange',ax=ax,label='Europe')
North_America.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Yellow',ax=ax,label='North America')
Oceania.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Blue',ax=ax,label='Oceania')
South_America.plot(kind='scatter',x="Life_expectancy",y="GDP_per_capita",color='Black',ax=ax,label='South America')

4.分析

通过以上的图形我们可以发现,非洲国家的人均GDP和人均普遍处于比较靠下的位置,其大多数国家的人均寿命都不足65岁;而相比较而言欧洲国家的这两项数据普遍处于世界前列(欧洲人民很幸福啊)。并且这两个大洲相对于其他大洲而言数据比较集中,比如我们身处的亚洲数据分散得比较开,这也说明亚洲各个国家之间发展不均衡。
同时我们也可以发现,其实人均寿命和人均GDP并没有正相关系存在,也就是说,你能活多久并不取决于你能挣多少钱。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容