{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-05-06T11:49:40.195103Z", "start_time": "2025-05-06T11:49:40.193162Z" } }, "source": [ "# 代码5-13\n", "# 导库\n", "from matplotlib import pyplot as plt\n", "import pandas as pd\n", "import seaborn as sns\n", "import warnings\n", "# 忽略所有警告\n", "warnings.filterwarnings(\"ignore\")" ], "outputs": [], "execution_count": 1 }, { "metadata": { "ExecuteTime": { "end_time": "2025-05-06T11:49:40.215751Z", "start_time": "2025-05-06T11:49:40.205742Z" } }, "cell_type": "code", "source": [ "# 设置中文字体\n", "from matplotlib import font_manager as fm\n", "import matplotlib as mpl\n", "font_path = '/System/Library/Fonts/STHeiti Medium.ttc'\n", "my_font = fm.FontProperties(fname=font_path)\n", "mpl.rcParams['font.family'] = my_font.get_name()\n", "mpl.rcParams['axes.unicode_minus'] = False" ], "id": "1fdc04b40026a38b", "outputs": [], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2025-05-06T11:49:40.291504Z", "start_time": "2025-05-06T11:49:40.262025Z" } }, "cell_type": "code", "source": [ "# 加载数据\n", "hr = pd.read_csv('./data/hr.csv', encoding='gbk')\n", "hr.head(3)" ], "id": "c1cbb2b07efac1d", "outputs": [ { "data": { "text/plain": [ " 用户编号 满意度 评分 总项目数 每月平均工作小时数(小时) 工龄(年) 工作事故 离职 5年内升职 部门 薪资\n", "0 1 0.38 0.53 2 157 3 0 1 0 销售部 低\n", "1 2 0.80 0.86 5 242 6 0 1 0 销售部 中\n", "2 3 0.11 0.88 7 242 4 0 1 0 销售部 中" ], "text/html": [ "
\n", " | 用户编号 | \n", "满意度 | \n", "评分 | \n", "总项目数 | \n", "每月平均工作小时数(小时) | \n", "工龄(年) | \n", "工作事故 | \n", "离职 | \n", "5年内升职 | \n", "部门 | \n", "薪资 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1 | \n", "0.38 | \n", "0.53 | \n", "2 | \n", "157 | \n", "3 | \n", "0 | \n", "1 | \n", "0 | \n", "销售部 | \n", "低 | \n", "
1 | \n", "2 | \n", "0.80 | \n", "0.86 | \n", "5 | \n", "242 | \n", "6 | \n", "0 | \n", "1 | \n", "0 | \n", "销售部 | \n", "中 | \n", "
2 | \n", "3 | \n", "0.11 | \n", "0.88 | \n", "7 | \n", "242 | \n", "4 | \n", "0 | \n", "1 | \n", "0 | \n", "销售部 | \n", "中 | \n", "