没有合适的资源?快使用搜索试试~ 我知道了~
pandas清洗数据
资源推荐
资源详情
资源评论
一、读取数据
In[2]:
import pandas as pd
df=pd.read_csv('/home/mw/input/tian3376/双十一淘宝美妆数据.csv')
df.head()
update_time id title price sale_count comment_count
店
名
0 2016/11/14 A18164178225
CHANDO/自然堂 雪
域精粹纯粹滋润霜
50g 补水保湿 滋润
水润面霜
139.0 26719.0 2704.0
自
然
堂
1 2016/11/14 A18177105952
CHANDO/自然堂凝
时鲜颜肌活乳液
120ML 淡化细纹补
水滋润专柜正品
194.0 8122.0 1492.0
自
然
堂
2 2016/11/14 A18177226992
CHANDO/自然堂活
泉保湿修护精华水
(滋润型135ml 补水
控油爽肤水
99.0 12668.0 589.0
自
然
堂
3 2016/11/14 A18178033846
CHANDO/自然堂 男
士劲爽控油洁面膏
100g 深层清洁 男士
洗面奶
38.0 25805.0 4287.0
自
然
堂
4 2016/11/14 A18178045259
CHANDO/自然堂雪
域精粹纯粹滋润霜
(清爽型)50g补水
保湿滋润霜
139.0 5196.0 618.0
自
然
堂
In[3]:
df.info()
二、数据处理
1、修改数据字段
从上面可以看到,时间字段数据类型为object,我们应该修改为datetime,避免后续分析出现错误
In[4]:
df['update_time']=pd.to_datetime(df['update_time'])
df.info()
2、重复数据处理
In[5]:
df.drop_duplicates(inplace=True)
3、缺失值处理
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 27598 entries, 0 to 27597
Data columns (total 7 columns):
update_time 27598 non-null object
id 27598 non-null object
title 27598 non-null object
price 27598 non-null float64
sale_count 25244 non-null float64
comment_count 25244 non-null float64
店名 27598 non-null object
dtypes: float64(3), object(4)
memory usage: 1.5+ MB
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 27598 entries, 0 to 27597
Data columns (total 7 columns):
update_time 27598 non-null datetime64[ns]
id 27598 non-null object
title 27598 non-null object
price 27598 non-null float64
sale_count 25244 non-null float64
comment_count 25244 non-null float64
店名 27598 non-null object
dtypes: datetime64[ns](1), float64(3), object(3)
memory usage: 1.5+ MB
In[6]:
df.isnull().any(0)
In[7]:
df.describe()
发现有两列有缺失值,接着查看两列缺失值的众数
In[8]:
df['sale_count'].mode()
In[9]:
df['comment_count'].mode()
我们针对缺失值就填充0,
update_time False
id False
title False
price False
sale_count True
comment_count True
店名 False
dtype: bool
price sale_count comment_count
count 27512.000000 2.516200e+04 25162.000000
mean 363.423512 1.231605e+04 1121.741197
std 614.876153 5.241236e+04 5277.781581
min 1.000000 0.000000e+00 0.000000
25% 99.000000 2.780000e+02 21.000000
50% 205.000000 1.443000e+03 153.000000
75% 390.000000 6.353000e+03 669.000000
max 11100.000000 1.923160e+06 202930.000000
0 0.0
dtype: float64
0 0.0
dtype: float64
剩余19页未读,继续阅读
资源评论
傻傻的小丫头
- 粉丝: 8
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功