{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using matplotlib backend: MacOSX\n",
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab\n",
"%matplotlib inline\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import stats\n",
"from matplotlib import colors\n",
"\n",
"data = pd.read_csv(\"Tennis players 2017-09.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
"
\n",
" \n",
" | \n",
" DOB | \n",
" RANK | \n",
" HEIGHT | \n",
" Weight | \n",
"
\n",
" \n",
" DOB | \n",
" 1 | \n",
" 0.277766 | \n",
" 0.139684 | \n",
" -0.030479 | \n",
"
\n",
" RANK | \n",
" 0.277766 | \n",
" 1 | \n",
" -0.16755 | \n",
" -0.121946 | \n",
"
\n",
" HEIGHT | \n",
" 0.139684 | \n",
" -0.16755 | \n",
" 1 | \n",
" 0.779526 | \n",
"
\n",
" Weight | \n",
" -0.030479 | \n",
" -0.121946 | \n",
" 0.779526 | \n",
" 1 | \n",
"
\n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def background_gradient(s, m, M, cmap='Wistia', low=0, high=0):\n",
" rng = M - m\n",
" norm = colors.Normalize(m - (rng * low),\n",
" M + (rng * high))\n",
" normed = norm(s.values)\n",
" c = [colors.rgb2hex(x) for x in plt.cm.get_cmap(cmap)(normed)]\n",
" return ['background-color: %s' % color for color in c]\n",
"\n",
"data = data[[\"SEX\", \"DOB\", \"RANK\", \"HANDED\", \"Country\", \"HEIGHT\", \"Weight\"]]\n",
"data.drop_duplicates\n",
"\n",
"pearson = data.corr()\n",
"pearson.style.apply(background_gradient,\n",
" cmap='Wistia',\n",
" m=pearson.min().min(),\n",
" M=pearson.max().max()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" | \n",
" DOB | \n",
" RANK | \n",
" HEIGHT | \n",
" Weight | \n",
"
\n",
" \n",
" DOB | \n",
" 1 | \n",
" 0.280386 | \n",
" 0.122412 | \n",
" 0.00769861 | \n",
"
\n",
" RANK | \n",
" 0.280386 | \n",
" 1 | \n",
" -0.160006 | \n",
" -0.0908714 | \n",
"
\n",
" HEIGHT | \n",
" 0.122412 | \n",
" -0.160006 | \n",
" 1 | \n",
" 0.739246 | \n",
"
\n",
" Weight | \n",
" 0.00769861 | \n",
" -0.0908714 | \n",
" 0.739246 | \n",
" 1 | \n",
"
\n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spearman = data.corr(method=\"spearman\")\n",
"spearman.style.apply(background_gradient,\n",
" cmap='Wistia',\n",
" m=spearman.min().min(),\n",
" M=spearman.max().max()\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}