214 lines
4.2 KiB
Plaintext
214 lines
4.2 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import pandas as pd\n",
|
||
|
"import matplotlib.pyplot as plt"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"%matplotlib inline\n",
|
||
|
"%config InlineBackend.figure_format='svg'"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"plt.rcParams['font.sans-serif'] = 'FZJKai-Z03S'\n",
|
||
|
"plt.rcParams['axes.unicode_minus'] = False"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser1 = pd.Series(data=[320, 180, 300, 405], index=['一季度', '二季度', '三季度', '四季度'])\n",
|
||
|
"ser1"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser2 = pd.Series({'一季度': 320, '二季度': 180, '三季度': 300, '四季度': 405})\n",
|
||
|
"ser2"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"print(ser2[0], ser2[2], ser2[-1])\n",
|
||
|
"ser2[0], ser2[-1] = 350, 360 \n",
|
||
|
"print(ser2)"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"print(ser2['一季度'], ser2['三季度'])\n",
|
||
|
"ser2['一季度'] = 380\n",
|
||
|
"print(ser2)"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"print(ser2[1:3])\n",
|
||
|
"print(ser2['二季度': '四季度'])\n",
|
||
|
"ser2[1:3] = 400, 500\n",
|
||
|
"print(ser2)"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"print(ser2[['二季度', '四季度']])\n",
|
||
|
"ser2[['二季度', '四季度']] = 500, 520\n",
|
||
|
"print(ser2)"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"print(ser2[ser2 >= 500])"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"# 求和\n",
|
||
|
"print(ser2.sum())\n",
|
||
|
"# 求均值\n",
|
||
|
"print(ser2.mean())\n",
|
||
|
"# 求最大\n",
|
||
|
"print(ser2.max())\n",
|
||
|
"# 求最小\n",
|
||
|
"print(ser2.min())\n",
|
||
|
"# 计数\n",
|
||
|
"print(ser2.count())\n",
|
||
|
"# 求标准差\n",
|
||
|
"print(ser2.std())\n",
|
||
|
"# 求方差\n",
|
||
|
"print(ser2.var())\n",
|
||
|
"# 求中位数\n",
|
||
|
"print(ser2.median())"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser2.describe()"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser3 = pd.Series(data=['apple', 'banana', 'apple', 'pitaya', 'apple', 'pitaya', 'durian'])\n",
|
||
|
"ser3.value_counts()"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser4 = pd.Series(data=[10, 20, np.NaN, 30, np.NaN])\n",
|
||
|
"ser4.dropna()"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser4.fillna(value=40)"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"source": [
|
||
|
"ser4.fillna(method='ffill')"
|
||
|
],
|
||
|
"outputs": [],
|
||
|
"metadata": {}
|
||
|
}
|
||
|
],
|
||
|
"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.7"
|
||
|
},
|
||
|
"toc": {
|
||
|
"base_numbering": 1,
|
||
|
"nav_menu": {},
|
||
|
"number_sections": true,
|
||
|
"sideBar": true,
|
||
|
"skip_h1_title": false,
|
||
|
"title_cell": "Table of Contents",
|
||
|
"title_sidebar": "Contents",
|
||
|
"toc_cell": false,
|
||
|
"toc_position": {},
|
||
|
"toc_section_display": true,
|
||
|
"toc_window_display": false
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|