admin管理员组文章数量:1660200
一、欧洲人口普查数据分析
本案例重点在于对数据质量的清洗、转换,、可视化。
import os #导入需要的库
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")
os.chdir(r"D:\Datalu\File") #指定工作目录
%matplotlib inline #可视化设置
plt.rcParams["font.sans-serif"] = ["KAITI"]
plt.rcParams["axes.unicode_minus"] = False
1.1 导入数据,并查看前五行
df = pd.read_csv('european_cities.csv')
df.head()
Rank | City | State | Population | Date of census/estimate | |
---|---|---|---|---|---|
0 | 1 | London[2] | United Kingdom | 8,615,246 | 1-Jun-14 |
1 | 2 | Berlin | Germany | 3,437,916 | 31-May-14 |
2 | 3 | Madrid | Spain | 3,165,235 | 1-Jan-14 |
3 | 4 | Rome | Italy | 2,872,086 | 30-Sep-14 |
4 | 5 | Paris | France | 2,273,305 | 1-Jan-13 |
1.2 拷贝数据
df1 =df.copy()
二、提出分析问题
问题提出:
1、查看数据类型
2、查看Shape
3、是否有缺失值
4、对数据进行清洗
5、重新设置索引
6、查看哪个国家城市最多
7、查看哪个国家人口最多
2.1 查看数据类型
#1、查看数据类型
df.info(memory_usage="deep")
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 105 entries, 0 to 104
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Rank 105 non-null int64
1 City 105 non-null object
2 State 105 non-null object
3 Population 105 non-null object
4 Date of census/estimate 105 non-null object
dtypes: int64(1), object(4)
memory usage: 27.9 KB
#方法一用astype强制转换
df1["Date of census/estimate"] = df1["Date of census/estimate"].astype("datetime64")
df1.info(memory_usage="deep")
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 105 entries, 0 to 104
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Rank 105 non-null int64
1 City 105 non-null object
2 State 105 non-null object
3 Population 105 non-null object
4 Date of census/estimate 105 non-null datetime64[ns]
dtypes: datetime64[ns](1), int64(1), object(3)
memory usage: 22.0 KB
#方法二用to_datetime转换
df1["Date of census/estimate"] = pd.to_datetime(df1[
版权声明:本文标题:1001系列之案例0003如何对欧洲人口普查数据集整理挖掘 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729850632a1215359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论