回答編集履歴
1
コード追加
answer
CHANGED
@@ -1,1 +1,29 @@
|
|
1
|
+
```python
|
2
|
+
import pandas as pd
|
3
|
+
from pprint import pprint
|
4
|
+
|
5
|
+
df = pd.read_csv("adult.data", header=None, delimiter=r"\s+", )
|
6
|
+
df.columns = ['age', 'workclass', 'fnlwgt', 'education', 'education-num',
|
7
|
+
'marital-status', 'occupation', 'relationship', 'race',
|
8
|
+
'sex', 'capital-gain', 'capital-loss', 'hours-per-week',
|
9
|
+
'native-country', 'income_class']
|
10
|
+
|
11
|
+
df["income_class"] = df["income_class"].map({"<=50K": 0, ">50K": 1})
|
12
|
+
pprint(df["income_class"].head(10))
|
13
|
+
"""
|
14
|
+
0 0
|
15
|
+
1 0
|
16
|
+
2 0
|
17
|
+
3 0
|
18
|
+
4 0
|
19
|
+
5 0
|
20
|
+
6 0
|
21
|
+
7 1
|
22
|
+
8 1
|
23
|
+
9 1
|
24
|
+
Name: income_class, dtype: int64
|
25
|
+
|
26
|
+
"""
|
27
|
+
```
|
28
|
+
|
1
29
|
[Analysis of the Adult data set from UCI Machine Learning Repository](http://blog.pangyanhan.com/posts/2017-02-15-analysis-of-the-adult-data-set-from-uci-machine-learning-repository.ipynb.html)
|