{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### 白人和黑人在求职路上会有种族的歧视吗?" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idadeducationofjobsyearsexphonorsvolunteermilitaryempholesoccupspecific...compreqorgreqmanuftranscombankrealtradebusserviceothservicemissindownership
0b1426000117...1.00.01.00.00.00.00.00.00.0
1b13360110316...1.00.01.00.00.00.00.00.00.0
2b1416000019...1.00.01.00.00.00.00.00.00.0
3b13460101313...1.00.01.00.00.00.00.00.00.0
4b133220000313...1.01.00.00.00.00.00.01.00.0Nonprofit
\n", "

5 rows × 65 columns

\n", "
" ], "text/plain": [ " id ad education ofjobs yearsexp honors volunteer military empholes \\\n", "0 b 1 4 2 6 0 0 0 1 \n", "1 b 1 3 3 6 0 1 1 0 \n", "2 b 1 4 1 6 0 0 0 0 \n", "3 b 1 3 4 6 0 1 0 1 \n", "4 b 1 3 3 22 0 0 0 0 \n", "\n", " occupspecific ... compreq orgreq manuf transcom bankreal trade \\\n", "0 17 ... 1.0 0.0 1.0 0.0 0.0 0.0 \n", "1 316 ... 1.0 0.0 1.0 0.0 0.0 0.0 \n", "2 19 ... 1.0 0.0 1.0 0.0 0.0 0.0 \n", "3 313 ... 1.0 0.0 1.0 0.0 0.0 0.0 \n", "4 313 ... 1.0 1.0 0.0 0.0 0.0 0.0 \n", "\n", " busservice othservice missind ownership \n", "0 0.0 0.0 0.0 \n", "1 0.0 0.0 0.0 \n", "2 0.0 0.0 0.0 \n", "3 0.0 0.0 0.0 \n", "4 0.0 1.0 0.0 Nonprofit \n", "\n", "[5 rows x 65 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.io.stata.read_stata('us_job_market_discrimination.dta')\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "blacks = data[data.race=='b'] # 黑人\n", "whites = data[data.race=='w'] # 白人" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "count 2435.000000\n", "mean 0.064476\n", "std 0.245649\n", "min 0.000000\n", "25% 0.000000\n", "50% 0.000000\n", "75% 0.000000\n", "max 1.000000\n", "Name: call, dtype: float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "blacks.call.describe() # call为1则是被录取,为0则是不录取" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "count 2435.000000\n", "mean 0.096509\n", "std 0.295346\n", "min 0.000000\n", "25% 0.000000\n", "50% 0.000000\n", "75% 0.000000\n", "max 1.000000\n", "Name: call, dtype: float64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "whites.call.describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "白人的录取均值更高,我们再查看其它的指标,确认是到底是不是因为肤色" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 卡方检验\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 假设检验\n", "