腾讯云开发者社区
数据分析之数据清洗
数据分析之数据清洗
In [144]:
#读取数据
import matplotlib.pyplot as plt
%matplotlib notebook
import seaborn as sns #要注意的是一旦导入了seaborn,matplotlib的默认作图风格就会被覆盖成seaborn的格式
import pandas
users=pandas.read_csv("./train_users_2.csv/train_users_2.csv")
In [145]:
users.info() # 查看数据整体信息
users.head() # 查看前5个数据信息
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null object timestamp_first_active 213451 non-null int64 date_first_booking 88908 non-null object gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: float64(1), int64(2), object(13) memory usage: 15.5+ MB
Out[145]:
| id | date_account_created | timestamp_first_active | date_first_booking | gender | age | signup_method | signup_flow | language | affiliate_channel | affiliate_provider | first_affiliate_tracked | signup_app | first_device_type | first_browser | country_destination | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | gxn3p5htnn | 2010-06-28 | 20090319043255 | NaN | -unknown- | NaN | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | NDF | |
| 1 | 820tgsjxq7 | 2011-05-25 | 20090523174809 | NaN | MALE | 38.0 | 0 | en | seo | untracked | Web | Mac Desktop | Chrome | NDF | ||
| 2 | 4ft3gnwmtx | 2010-09-28 | 20090609231247 | 2010-08-02 | FEMALE | 56.0 | basic | 3 | en | direct | direct | untracked | Web | Windows Desktop | IE | US |
| 3 | bjjt8pjhuk | 2011-12-05 | 20091031060129 | 2012-09-08 | FEMALE | 42.0 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | other | |
| 4 | 87mebub9p4 | 2010-09-14 | 20091208061105 | 2010-02-18 | -unknown- | 41.0 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | US |
In [146]:
users["date_account_created"] = pandas.to_datetime(users["date_account_created"],format="%Y-%m-%d")
users["timestamp_first_active"] = pandas.to_datetime(users["timestamp_first_active"],format="%Y%m%d%H%M%S")
users["date_first_booking"] = pandas.to_datetime(users["date_first_booking"],format="%Y-%m-%d")
users.info()
users.head()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 17.1+ MB
Out[146]:
| id | date_account_created | timestamp_first_active | date_first_booking | gender | age | signup_method | signup_flow | language | affiliate_channel | affiliate_provider | first_affiliate_tracked | signup_app | first_device_type | first_browser | country_destination | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | gxn3p5htnn | 2010-06-28 | 2009-03-19 04:32:55 | NaT | -unknown- | NaN | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | NDF | |
| 1 | 820tgsjxq7 | 2011-05-25 | 2009-05-23 17:48:09 | NaT | MALE | 38.0 | 0 | en | seo | untracked | Web | Mac Desktop | Chrome | NDF | ||
| 2 | 4ft3gnwmtx | 2010-09-28 | 2009-06-09 23:12:47 | 2010-08-02 | FEMALE | 56.0 | basic | 3 | en | direct | direct | untracked | Web | Windows Desktop | IE | US |
| 3 | bjjt8pjhuk | 2011-12-05 | 2009-10-31 06:01:29 | 2012-09-08 | FEMALE | 42.0 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | other | |
| 4 | 87mebub9p4 | 2010-09-14 | 2009-12-08 06:11:05 | 2010-02-18 | -unknown- | 41.0 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | US |
In [147]:
users["age"] = users["age"].astype(dtype='str',errors="ignore")
users.info()
users.head()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 213451 non-null object signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), int64(1), object(12) memory usage: 16.3+ MB
Out[147]:
| id | date_account_created | timestamp_first_active | date_first_booking | gender | age | signup_method | signup_flow | language | affiliate_channel | affiliate_provider | first_affiliate_tracked | signup_app | first_device_type | first_browser | country_destination | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | gxn3p5htnn | 2010-06-28 | 2009-03-19 04:32:55 | NaT | -unknown- | nan | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | NDF | |
| 1 | 820tgsjxq7 | 2011-05-25 | 2009-05-23 17:48:09 | NaT | MALE | 38.0 | 0 | en | seo | untracked | Web | Mac Desktop | Chrome | NDF | ||
| 2 | 4ft3gnwmtx | 2010-09-28 | 2009-06-09 23:12:47 | 2010-08-02 | FEMALE | 56.0 | basic | 3 | en | direct | direct | untracked | Web | Windows Desktop | IE | US |
| 3 | bjjt8pjhuk | 2011-12-05 | 2009-10-31 06:01:29 | 2012-09-08 | FEMALE | 42.0 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | other | |
| 4 | 87mebub9p4 | 2010-09-14 | 2009-12-08 06:11:05 | 2010-02-18 | -unknown- | 41.0 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | US |
In [148]:
users["age"] = users["age"].astype(dtype='float',errors="ignore")
users.info()
users.head()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 17.1+ MB
Out[148]:
| id | date_account_created | timestamp_first_active | date_first_booking | gender | age | signup_method | signup_flow | language | affiliate_channel | affiliate_provider | first_affiliate_tracked | signup_app | first_device_type | first_browser | country_destination | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | gxn3p5htnn | 2010-06-28 | 2009-03-19 04:32:55 | NaT | -unknown- | NaN | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | NDF | |
| 1 | 820tgsjxq7 | 2011-05-25 | 2009-05-23 17:48:09 | NaT | MALE | 38.0 | 0 | en | seo | untracked | Web | Mac Desktop | Chrome | NDF | ||
| 2 | 4ft3gnwmtx | 2010-09-28 | 2009-06-09 23:12:47 | 2010-08-02 | FEMALE | 56.0 | basic | 3 | en | direct | direct | untracked | Web | Windows Desktop | IE | US |
| 3 | bjjt8pjhuk | 2011-12-05 | 2009-10-31 06:01:29 | 2012-09-08 | FEMALE | 42.0 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | other | |
| 4 | 87mebub9p4 | 2010-09-14 | 2009-12-08 06:11:05 | 2010-02-18 | -unknown- | 41.0 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | US |
In [149]:
users["age"].dropna()
Out[149]:
1 38.0
2 56.0
3 42.0
4 41.0
6 46.0
7 47.0
8 50.0
9 46.0
10 36.0
11 47.0
13 37.0
14 36.0
15 33.0
17 31.0
19 29.0
21 30.0
22 40.0
24 40.0
25 26.0
27 32.0
28 35.0
29 37.0
30 42.0
31 31.0
32 31.0
33 29.0
34 59.0
35 49.0
36 31.0
37 30.0
...
213390 30.0
213391 29.0
213393 26.0
213395 33.0
213398 39.0
213400 53.0
213401 45.0
213402 32.0
213403 27.0
213405 23.0
213406 35.0
213407 21.0
213408 69.0
213409 28.0
213410 33.0
213412 50.0
213415 55.0
213417 46.0
213423 20.0
213424 32.0
213425 30.0
213430 19.0
213432 31.0
213439 43.0
213440 24.0
213441 34.0
213443 36.0
213445 23.0
213446 32.0
213448 32.0
Name: age, Length: 125461, dtype: float64
In [150]:
users["age"].describe()
Out[150]:
count 125461.000000 mean 49.668335 std 155.666612 min 1.000000 25% 28.000000 50% 34.000000 75% 43.000000 max 2014.000000 Name: age, dtype: float64
In [151]:
users.fillna(users["age"].mean()) # 填充平均值
Out[151]:
| id | date_account_created | timestamp_first_active | date_first_booking | gender | age | signup_method | signup_flow | language | affiliate_channel | affiliate_provider | first_affiliate_tracked | signup_app | first_device_type | first_browser | country_destination | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | gxn3p5htnn | 2010-06-28 | 2009-03-19 04:32:55 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | NDF | |
| 1 | 820tgsjxq7 | 2011-05-25 | 2009-05-23 17:48:09 | 1970-01-01 00:00:00.000000049 | MALE | 38.000000 | 0 | en | seo | untracked | Web | Mac Desktop | Chrome | NDF | ||
| 2 | 4ft3gnwmtx | 2010-09-28 | 2009-06-09 23:12:47 | 2010-08-02 00:00:00.000000000 | FEMALE | 56.000000 | basic | 3 | en | direct | direct | untracked | Web | Windows Desktop | IE | US |
| 3 | bjjt8pjhuk | 2011-12-05 | 2009-10-31 06:01:29 | 2012-09-08 00:00:00.000000000 | FEMALE | 42.000000 | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | other | |
| 4 | 87mebub9p4 | 2010-09-14 | 2009-12-08 06:11:05 | 2010-02-18 00:00:00.000000000 | -unknown- | 41.000000 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | US |
| 5 | osr2jwljor | 2010-01-01 | 2010-01-01 21:56:19 | 2010-01-02 00:00:00.000000000 | -unknown- | 49.668335 | basic | 0 | en | other | other | omg | Web | Mac Desktop | Chrome | US |
| 6 | lsw9q7uk0j | 2010-01-02 | 2010-01-02 01:25:58 | 2010-01-05 00:00:00.000000000 | FEMALE | 46.000000 | basic | 0 | en | other | craigslist | untracked | Web | Mac Desktop | Safari | US |
| 7 | 0d01nltbrs | 2010-01-03 | 2010-01-03 19:19:05 | 2010-01-13 00:00:00.000000000 | FEMALE | 47.000000 | basic | 0 | en | direct | direct | omg | Web | Mac Desktop | Safari | US |
| 8 | a1vcnhxeij | 2010-01-04 | 2010-01-04 00:42:11 | 2010-07-29 00:00:00.000000000 | FEMALE | 50.000000 | basic | 0 | en | other | craigslist | untracked | Web | Mac Desktop | Safari | US |
| 9 | 6uh8zyj2gn | 2010-01-04 | 2010-01-04 02:37:58 | 2010-01-04 00:00:00.000000000 | -unknown- | 46.000000 | basic | 0 | en | other | craigslist | omg | Web | Mac Desktop | Firefox | US |
| 10 | yuuqmid2rp | 2010-01-04 | 2010-01-04 19:42:51 | 2010-01-06 00:00:00.000000000 | FEMALE | 36.000000 | basic | 0 | en | other | craigslist | untracked | Web | Mac Desktop | Firefox | US |
| 11 | om1ss59ys8 | 2010-01-05 | 2010-01-05 05:18:12 | 1970-01-01 00:00:00.000000049 | FEMALE | 47.000000 | basic | 0 | en | other | craigslist | untracked | Web | iPhone | -unknown- | NDF |
| 12 | k6np330cm1 | 2010-01-05 | 2010-01-05 06:08:59 | 2010-01-18 00:00:00.000000000 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | 49.6683 | Web | Other/Unknown | -unknown- | FR |
| 13 | dy3rgx56cu | 2010-01-05 | 2010-01-05 08:32:59 | 1970-01-01 00:00:00.000000049 | FEMALE | 37.000000 | basic | 0 | en | other | craigslist | linked | Web | Mac Desktop | Firefox | NDF |
| 14 | ju3h98ch3w | 2010-01-07 | 2010-01-07 05:58:20 | 1970-01-01 00:00:00.000000049 | FEMALE | 36.000000 | basic | 0 | en | other | craigslist | untracked | Web | iPhone | Mobile Safari | NDF |
| 15 | v4d5rl22px | 2010-01-07 | 2010-01-07 20:45:55 | 2010-01-08 00:00:00.000000000 | FEMALE | 33.000000 | basic | 0 | en | direct | direct | untracked | Web | Windows Desktop | Chrome | CA |
| 16 | 2dwbwkx056 | 2010-01-07 | 2010-01-07 21:51:25 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | other | craigslist | 49.6683 | Web | Other/Unknown | -unknown- | NDF |
| 17 | frhre329au | 2010-01-07 | 2010-01-07 22:46:25 | 2010-01-09 00:00:00.000000000 | -unknown- | 31.000000 | basic | 0 | en | other | craigslist | 49.6683 | Web | Other/Unknown | -unknown- | US |
| 18 | cxlg85pg1r | 2010-01-08 | 2010-01-08 01:56:41 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | seo | 49.6683 | Web | Other/Unknown | -unknown- | NDF | |
| 19 | gdka1q5ktd | 2010-01-10 | 2010-01-10 01:08:17 | 2010-01-10 00:00:00.000000000 | FEMALE | 29.000000 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Chrome | FR |
| 20 | qdubonn3uk | 2010-01-10 | 2010-01-10 15:21:20 | 2010-01-18 00:00:00.000000000 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | 49.6683 | Web | Other/Unknown | -unknown- | US |
| 21 | qsibmuz9sx | 2010-01-10 | 2010-01-10 22:09:41 | 2010-01-11 00:00:00.000000000 | MALE | 30.000000 | basic | 0 | en | direct | direct | linked | Web | Mac Desktop | Chrome | US |
| 22 | 80f7dwscrn | 2010-01-11 | 2010-01-11 03:14:38 | 2010-01-11 00:00:00.000000000 | -unknown- | 40.000000 | basic | 0 | en | seo | untracked | Web | iPhone | -unknown- | US | |
| 23 | jha93x042q | 2010-01-11 | 2010-01-11 22:40:15 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | other | craigslist | untracked | Web | Mac Desktop | Safari | NDF |
| 24 | 7i49vnuav6 | 2010-01-11 | 2010-01-11 23:08:08 | 1970-01-01 00:00:00.000000049 | FEMALE | 40.000000 | basic | 0 | en | seo | untracked | Web | Mac Desktop | Firefox | NDF | |
| 25 | al8bcetz0g | 2010-01-12 | 2010-01-12 13:14:44 | 2010-01-15 00:00:00.000000000 | FEMALE | 26.000000 | basic | 0 | en | other | craigslist | untracked | Web | Mac Desktop | Chrome | FR |
| 26 | bjg0m5otl3 | 2010-01-12 | 2010-01-12 15:54:20 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | other | other | untracked | Web | Other/Unknown | -unknown- | NDF |
| 27 | hfrl5gle36 | 2010-01-12 | 2010-01-12 20:59:49 | 2010-01-22 00:00:00.000000000 | FEMALE | 32.000000 | basic | 0 | en | other | craigslist | untracked | Web | Desktop (Other) | Chrome | US |
| 28 | tp6x3md0n4 | 2010-01-13 | 2010-01-13 04:46:50 | 2010-01-13 00:00:00.000000000 | -unknown- | 35.000000 | basic | 0 | en | direct | direct | 49.6683 | Web | Other/Unknown | -unknown- | FR |
| 29 | hql77nu2lk | 2010-01-13 | 2010-01-13 06:43:33 | 2010-01-19 00:00:00.000000000 | -unknown- | 37.000000 | basic | 0 | en | direct | direct | untracked | Web | Android Tablet | -unknown- | US |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 213421 | c98s3h7kgj | 2014-06-30 | 2014-06-30 23:11:37 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | linked | Web | Mac Desktop | Firefox | NDF |
| 213422 | ytmpiwb8hj | 2014-06-30 | 2014-06-30 23:12:46 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | untracked | Web | Windows Desktop | IE | NDF |
| 213423 | 3dx1jk6yk2 | 2014-06-30 | 2014-06-30 23:15:48 | 1970-01-01 00:00:00.000000049 | FEMALE | 20.000000 | 25 | en | direct | direct | untracked | iOS | iPhone | -unknown- | NDF | |
| 213424 | hcfj07iowv | 2014-06-30 | 2014-06-30 23:18:59 | 1970-01-01 00:00:00.000000049 | FEMALE | 32.000000 | 0 | en | direct | direct | linked | Web | Windows Desktop | Chrome | NDF | |
| 213425 | l1f71f9vsj | 2014-06-30 | 2014-06-30 23:21:19 | 1970-01-01 00:00:00.000000049 | FEMALE | 30.000000 | 0 | en | direct | direct | linked | Web | Windows Desktop | Chrome | NDF | |
| 213426 | 15bj4ahmhf | 2014-06-30 | 2014-06-30 23:23:31 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | untracked | Moweb | Android Phone | Chrome Mobile | NDF |
| 213427 | qwpybxfjdl | 2014-06-30 | 2014-06-30 23:25:39 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | linked | Web | Desktop (Other) | Chrome | NDF |
| 213428 | k4t61wuvyq | 2014-06-30 | 2014-06-30 23:26:34 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 23 | en | direct | direct | untracked | Android | Android Phone | -unknown- | NDF |
| 213429 | mhh7b52z44 | 2014-06-30 | 2014-06-30 23:27:12 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 25 | en | direct | direct | untracked | iOS | iPhone | -unknown- | NDF |
| 213430 | 79wk7k2k5t | 2014-06-30 | 2014-06-30 23:31:32 | 1970-01-01 00:00:00.000000049 | -unknown- | 19.000000 | basic | 0 | en | direct | direct | linked | Web | Mac Desktop | Chrome | NDF |
| 213431 | ftwmocvwlq | 2014-06-30 | 2014-06-30 23:32:03 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | untracked | Web | Windows Desktop | Firefox | NDF |
| 213432 | rg7ayg1tob | 2014-06-30 | 2014-06-30 23:32:24 | 1970-01-01 00:00:00.000000049 | MALE | 31.000000 | 0 | en | direct | direct | tracked-other | Web | Mac Desktop | Safari | NDF | |
| 213433 | 2f24umzkuv | 2014-06-30 | 2014-06-30 23:34:27 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | sem-brand | untracked | Web | iPad | Mobile Safari | NDF | |
| 213434 | or77n2ojuj | 2014-06-30 | 2014-06-30 23:36:40 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | seo | product | Web | Mac Desktop | Chrome | NDF | |
| 213435 | 0a5bnb9bs4 | 2014-06-30 | 2014-06-30 23:38:51 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | seo | untracked | Web | Windows Desktop | Chrome | NDF | |
| 213436 | 6fzrn49sfn | 2014-06-30 | 2014-06-30 23:41:13 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 25 | en | direct | direct | untracked | iOS | iPhone | -unknown- | NDF |
| 213437 | r0jq0devgy | 2014-06-30 | 2014-06-30 23:42:43 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 23 | en | direct | direct | untracked | Android | Android Tablet | -unknown- | NDF |
| 213438 | v5lq9bj8gv | 2014-06-30 | 2014-06-30 23:44:29 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 25 | en | direct | direct | untracked | iOS | iPhone | -unknown- | NDF |
| 213439 | msucfwmlzc | 2014-06-30 | 2014-06-30 23:47:29 | 2015-03-16 00:00:00.000000000 | MALE | 43.000000 | basic | 0 | en | direct | direct | untracked | Web | Windows Desktop | Firefox | US |
| 213440 | 04y8115avm | 2014-06-30 | 2014-06-30 23:49:33 | 1970-01-01 00:00:00.000000049 | FEMALE | 24.000000 | basic | 25 | en | direct | direct | untracked | iOS | iPhone | Mobile Safari | NDF |
| 213441 | omlc9iku7t | 2014-06-30 | 2014-06-30 23:51:51 | 2014-08-13 00:00:00.000000000 | FEMALE | 34.000000 | basic | 0 | en | direct | direct | linked | Web | Mac Desktop | Chrome | ES |
| 213442 | rf0ay567js | 2014-06-30 | 2014-06-30 23:53:09 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | sem-brand | omg | Web | Mac Desktop | Chrome | NDF | |
| 213443 | 0k26r3mir0 | 2014-06-30 | 2014-06-30 23:53:40 | 2014-07-13 00:00:00.000000000 | FEMALE | 36.000000 | basic | 0 | en | sem-brand | linked | Web | Mac Desktop | Safari | US | |
| 213444 | 40o1ivh6cb | 2014-06-30 | 2014-06-30 23:53:52 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | linked | Web | Windows Desktop | Chrome | NDF |
| 213445 | qbxza0xojf | 2014-06-30 | 2014-06-30 23:55:47 | 2014-07-02 00:00:00.000000000 | FEMALE | 23.000000 | basic | 0 | en | sem-brand | omg | Web | Windows Desktop | IE | US | |
| 213446 | zxodksqpep | 2014-06-30 | 2014-06-30 23:56:36 | 1970-01-01 00:00:00.000000049 | MALE | 32.000000 | basic | 0 | en | sem-brand | omg | Web | Mac Desktop | Safari | NDF | |
| 213447 | mhewnxesx9 | 2014-06-30 | 2014-06-30 23:57:19 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 0 | en | direct | direct | linked | Web | Windows Desktop | Chrome | NDF |
| 213448 | 6o3arsjbb4 | 2014-06-30 | 2014-06-30 23:57:54 | 1970-01-01 00:00:00.000000049 | -unknown- | 32.000000 | basic | 0 | en | direct | direct | untracked | Web | Mac Desktop | Firefox | NDF |
| 213449 | jh95kwisub | 2014-06-30 | 2014-06-30 23:58:22 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 25 | en | other | other | tracked-other | iOS | iPhone | Mobile Safari | NDF |
| 213450 | nw9fwlyb5f | 2014-06-30 | 2014-06-30 23:58:24 | 1970-01-01 00:00:00.000000049 | -unknown- | 49.668335 | basic | 25 | en | direct | direct | untracked | iOS | iPhone | -unknown- | NDF |
213451 rows × 16 columns
In [152]:
users.info()
users["id"] = users["id"].drop_duplicates() # 去除重复数据
users.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 17.1+ MB <class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 17.1+ MB
In [156]:
import seaborn
seaborn.distplot(users["age"].dropna())
Out[156]:
<matplotlib.axes._subplots.AxesSubplot at 0x406f0ef0>
In [157]:
seaborn.boxplot(users["age"].dropna())
Out[157]:
<matplotlib.axes._subplots.AxesSubplot at 0x40746b90>
In [158]:
users.info()
users=users[users["age"]<120]
users.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 213451 entries, 0 to 213450 Data columns (total 16 columns): id 213451 non-null object date_account_created 213451 non-null datetime64[ns] timestamp_first_active 213451 non-null datetime64[ns] date_first_booking 88908 non-null datetime64[ns] gender 213451 non-null object age 125461 non-null float64 signup_method 213451 non-null object signup_flow 213451 non-null int64 language 213451 non-null object affiliate_channel 213451 non-null object affiliate_provider 213451 non-null object first_affiliate_tracked 207386 non-null object signup_app 213451 non-null object first_device_type 213451 non-null object first_browser 213451 non-null object country_destination 213451 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 17.1+ MB <class 'pandas.core.frame.DataFrame'> Int64Index: 124680 entries, 1 to 213448 Data columns (total 16 columns): id 124680 non-null object date_account_created 124680 non-null datetime64[ns] timestamp_first_active 124680 non-null datetime64[ns] date_first_booking 68156 non-null datetime64[ns] gender 124680 non-null object age 124680 non-null float64 signup_method 124680 non-null object signup_flow 124680 non-null int64 language 124680 non-null object affiliate_channel 124680 non-null object affiliate_provider 124680 non-null object first_affiliate_tracked 122682 non-null object signup_app 124680 non-null object first_device_type 124680 non-null object first_browser 124680 non-null object country_destination 124680 non-null object dtypes: datetime64[ns](3), float64(1), int64(1), object(11) memory usage: 10.9+ MB
六、git
git: https://coding.net/u/RuoYun/p/Python-of-machine-learning/git/tree/master
更多推荐
- · Elasticsearch复杂数据类型终极指南:从入门到精通
- · 终极指南:Flink SQL连接器版本管理从混乱到有序的升级之路
- · 如何快速搭建Neon无服务器PostgreSQL:面向初学者的完整指南
2629
0
0
- 0
扫一扫分享内容
分享
回到
顶部
顶部
所有评论(0)