{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from pandas import Series,DataFrame"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"Math 120\n",
"Python 136\n",
"En 128\n",
"Chinese 99\n",
"dtype: int64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 创建\n",
"# Series是一维的数据\n",
"s = Series(data = [120,136,128,99],index = ['Math','Python','En','Chinese'])\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(4,)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.shape"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([120, 136, 128, 99], dtype=int64)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v = s.values\n",
"v"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(v)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120.75"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.mean()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"136"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.max()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15.903353943953666"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.std()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Math 14400\n",
"Python 18496\n",
"En 16384\n",
"Chinese 9801\n",
"dtype: int64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.pow(2)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Python | \n",
" En | \n",
" Math | \n",
"
\n",
" \n",
" \n",
" \n",
" a | \n",
" 113 | \n",
" 116 | \n",
" 75 | \n",
"
\n",
" \n",
" b | \n",
" 19 | \n",
" 145 | \n",
" 23 | \n",
"
\n",
" \n",
" c | \n",
" 57 | \n",
" 107 | \n",
" 113 | \n",
"
\n",
" \n",
" d | \n",
" 95 | \n",
" 3 | \n",
" 66 | \n",
"
\n",
" \n",
" e | \n",
" 28 | \n",
" 121 | \n",
" 120 | \n",
"
\n",
" \n",
" f | \n",
" 141 | \n",
" 85 | \n",
" 132 | \n",
"
\n",
" \n",
" h | \n",
" 124 | \n",
" 39 | \n",
" 10 | \n",
"
\n",
" \n",
" i | \n",
" 80 | \n",
" 35 | \n",
" 17 | \n",
"
\n",
" \n",
" j | \n",
" 68 | \n",
" 99 | \n",
" 31 | \n",
"
\n",
" \n",
" k | \n",
" 74 | \n",
" 12 | \n",
" 11 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Python En Math\n",
"a 113 116 75\n",
"b 19 145 23\n",
"c 57 107 113\n",
"d 95 3 66\n",
"e 28 121 120\n",
"f 141 85 132\n",
"h 124 39 10\n",
"i 80 35 17\n",
"j 68 99 31\n",
"k 74 12 11"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# DataFrame是二维的数据\n",
"# excel就非常相似\n",
"# 所有进行数据分析,数据挖掘的工具最基础的结果:行和列,行表示样本,列表示的是属性\n",
"df = DataFrame(data = np.random.randint(0,150,size = (10,3)),index = list('abcdefhijk'),columns=['Python','En','Math'])\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"(10, 3)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"array([[113, 116, 75],\n",
" [ 19, 145, 23],\n",
" [ 57, 107, 113],\n",
" [ 95, 3, 66],\n",
" [ 28, 121, 120],\n",
" [141, 85, 132],\n",
" [124, 39, 10],\n",
" [ 80, 35, 17],\n",
" [ 68, 99, 31],\n",
" [ 74, 12, 11]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v = df.values\n",
"v"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 79.9\n",
"En 76.2\n",
"Math 59.8\n",
"dtype: float64"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.mean()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 141\n",
"En 145\n",
"Math 132\n",
"dtype: int32"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.max()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Python | \n",
" En | \n",
" Math | \n",
"
\n",
" \n",
" \n",
" \n",
" a | \n",
" 113 | \n",
" 116 | \n",
" 75 | \n",
"
\n",
" \n",
" b | \n",
" 19 | \n",
" 145 | \n",
" 23 | \n",
"
\n",
" \n",
" c | \n",
" 57 | \n",
" 107 | \n",
" 113 | \n",
"
\n",
" \n",
" d | \n",
" 95 | \n",
" 3 | \n",
" 66 | \n",
"
\n",
" \n",
" e | \n",
" 28 | \n",
" 121 | \n",
" 120 | \n",
"
\n",
" \n",
" f | \n",
" 141 | \n",
" 85 | \n",
" 132 | \n",
"
\n",
" \n",
" h | \n",
" 124 | \n",
" 39 | \n",
" 10 | \n",
"
\n",
" \n",
" i | \n",
" 80 | \n",
" 35 | \n",
" 17 | \n",
"
\n",
" \n",
" j | \n",
" 68 | \n",
" 99 | \n",
" 31 | \n",
"
\n",
" \n",
" k | \n",
" 74 | \n",
" 12 | \n",
" 11 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Python En Math\n",
"a 113 116 75\n",
"b 19 145 23\n",
"c 57 107 113\n",
"d 95 3 66\n",
"e 28 121 120\n",
"f 141 85 132\n",
"h 124 39 10\n",
"i 80 35 17\n",
"j 68 99 31\n",
"k 74 12 11"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 79.9\n",
"En 76.2\n",
"Math 59.8\n",
"dtype: float64"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.mean(axis = 0)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 101.333333\n",
"b 62.333333\n",
"c 92.333333\n",
"d 54.666667\n",
"e 89.666667\n",
"f 119.333333\n",
"h 57.666667\n",
"i 44.000000\n",
"j 66.000000\n",
"k 32.333333\n",
"dtype: float64"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.mean(axis = 1)"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}