{
"cells": [
{
"cell_type": "markdown",
"id": "9cd25ae8-6076-41b4-b349-99850ac8204a",
"metadata": {},
"source": [
"# 1. Pandas数据基础"
]
},
{
"cell_type": "markdown",
"id": "a807c65a-87b7-4f3f-b4e9-3cd40729bcd5",
"metadata": {},
"source": [
"- Pandas侧重于数据分析:业务背景\n",
" -字段/行\n",
" - 统计\n",
" - 分组\n",
" - 争对列与行有运算的概念\n",
" - 存储多种用户类型"
]
},
{
"cell_type": "markdown",
"id": "12f1dbf1-6c50-443a-ad2e-fed7cb5957ec",
"metadata": {},
"source": [
"- 三个数据结构\n",
" - Series:一维\n",
" - `DataFrame:二维数据`\n",
" - Panel:三维数据"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "77ed3899-9333-4458-b611-6e43258196cc",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 列1 | \n",
" 列2 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 2 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 3 | \n",
"
\n",
" \n",
" 3 | \n",
" 4 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" 5 | \n",
" 5 | \n",
"
\n",
" \n",
" 5 | \n",
" 6 | \n",
" 6 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 列1 列2\n",
"0 1 1\n",
"1 2 2\n",
"2 3 3\n",
"3 4 4\n",
"4 5 5\n",
"5 6 6"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"# arr = [\n",
"# [1,2,3,4,5,6],\n",
"# [1,2,3,4,5,6]\n",
"# ]\n",
"arr = {\n",
" \"列1\":[1,2,3,4,5,6],\n",
" \"列2\":[1,2,3,4,5,6]\n",
"}\n",
"pd_data = pd.DataFrame(data=arr)\n",
"pd_data"
]
},
{
"cell_type": "markdown",
"id": "5db2700f-e34a-4d24-9ff6-8ec6fc0ada45",
"metadata": {},
"source": [
"# 加载数据"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "12871386-0042-43af-bd5f-8065699080da",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 经度 | \n",
" 维度 | \n",
" 保留 | \n",
" 海拔 | \n",
" 天数 | \n",
" 日期 | \n",
" 时间 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 39.999840 | \n",
" 116.325001 | \n",
" 0 | \n",
" 487 | \n",
" 39999.120220 | \n",
" 2009-07-05 | \n",
" 02:53:07 | \n",
"
\n",
" \n",
" 1 | \n",
" 39.999899 | \n",
" 116.324809 | \n",
" 0 | \n",
" 477 | \n",
" 39999.120278 | \n",
" 2009-07-05 | \n",
" 02:53:12 | \n",
"
\n",
" \n",
" 2 | \n",
" 40.000017 | \n",
" 116.324672 | \n",
" 0 | \n",
" 468 | \n",
" 39999.120336 | \n",
" 2009-07-05 | \n",
" 02:53:17 | \n",
"
\n",
" \n",
" 3 | \n",
" 40.000234 | \n",
" 116.324729 | \n",
" 0 | \n",
" 460 | \n",
" 39999.120394 | \n",
" 2009-07-05 | \n",
" 02:53:22 | \n",
"
\n",
" \n",
" 4 | \n",
" 40.000363 | \n",
" 116.324670 | \n",
" 0 | \n",
" 450 | \n",
" 39999.120451 | \n",
" 2009-07-05 | \n",
" 02:53:27 | \n",
"
\n",
" \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" 2307 | \n",
" 40.000403 | \n",
" 116.327255 | \n",
" 0 | \n",
" 149 | \n",
" 39999.322859 | \n",
" 2009-07-05 | \n",
" 07:44:55 | \n",
"
\n",
" \n",
" 2308 | \n",
" 40.000433 | \n",
" 116.327209 | \n",
" 0 | \n",
" 150 | \n",
" 39999.322917 | \n",
" 2009-07-05 | \n",
" 07:45:00 | \n",
"
\n",
" \n",
" 2309 | \n",
" 40.000443 | \n",
" 116.327186 | \n",
" 0 | \n",
" 150 | \n",
" 39999.322975 | \n",
" 2009-07-05 | \n",
" 07:45:05 | \n",
"
\n",
" \n",
" 2310 | \n",
" 40.000522 | \n",
" 116.327132 | \n",
" 0 | \n",
" 149 | \n",
" 39999.323032 | \n",
" 2009-07-05 | \n",
" 07:45:10 | \n",
"
\n",
" \n",
" 2311 | \n",
" 40.000543 | \n",
" 116.327148 | \n",
" 0 | \n",
" 150 | \n",
" 39999.323090 | \n",
" 2009-07-05 | \n",
" 07:45:15 | \n",
"
\n",
" \n",
"
\n",
"
2312 rows × 7 columns
\n",
"
"
],
"text/plain": [
" 经度 维度 保留 海拔 天数 日期 时间\n",
"0 39.999840 116.325001 0 487 39999.120220 2009-07-05 02:53:07\n",
"1 39.999899 116.324809 0 477 39999.120278 2009-07-05 02:53:12\n",
"2 40.000017 116.324672 0 468 39999.120336 2009-07-05 02:53:17\n",
"3 40.000234 116.324729 0 460 39999.120394 2009-07-05 02:53:22\n",
"4 40.000363 116.324670 0 450 39999.120451 2009-07-05 02:53:27\n",
"... ... ... .. ... ... ... ...\n",
"2307 40.000403 116.327255 0 149 39999.322859 2009-07-05 07:44:55\n",
"2308 40.000433 116.327209 0 150 39999.322917 2009-07-05 07:45:00\n",
"2309 40.000443 116.327186 0 150 39999.322975 2009-07-05 07:45:05\n",
"2310 40.000522 116.327132 0 149 39999.323032 2009-07-05 07:45:10\n",
"2311 40.000543 116.327148 0 150 39999.323090 2009-07-05 07:45:15\n",
"\n",
"[2312 rows x 7 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.read_csv(\"dataset/tra.plt\", skiprows=6, header=None, names=[\"经度\", \"维度\", \"保留\", \"海拔\", \"天数\", \"日期\", \"时间\"])\n",
"data"
]
},
{
"cell_type": "markdown",
"id": "825d873c-ea4d-478d-9ebd-954edbbbfeba",
"metadata": {},
"source": [
"# 数据可视化"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "112d77d5-326a-4157-8019-a1fb43c10167",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 39.99984 , 116.325001],\n",
" [ 39.999899, 116.324809],\n",
" [ 40.000017, 116.324672],\n",
" ...,\n",
" [ 40.000443, 116.327186],\n",
" [ 40.000522, 116.327132],\n",
" [ 40.000543, 116.327148]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[[\"经度\", \"维度\"]].values"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f7b1b2d5-bbed-4c7e-9142-dc1e07878fce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2312, 2)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[[\"经度\", \"维度\"]].shape"
]
},
{
"cell_type": "markdown",
"id": "cb73bdd9-46c6-452d-b53b-ad0b17e90ac2",
"metadata": {},
"source": [
"# 数据分析"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "6f195731-0957-44fd-99c7-5d5dfffab306",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 经度 | \n",
" 维度 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 39.999840 | \n",
" 116.325001 | \n",
"
\n",
" \n",
" 5 | \n",
" 40.000565 | \n",
" 116.324806 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 经度 维度\n",
"0 39.999840 116.325001\n",
"5 40.000565 116.324806"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.loc[[0, 5], [\"经度\",\"维度\"]]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c6f51cfd-b901-496f-b4da-1984f43f4914",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 经度 | \n",
" 维度 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 39.999840 | \n",
" 116.325001 | \n",
"
\n",
" \n",
" 5 | \n",
" 40.000565 | \n",
" 116.324806 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 经度 维度\n",
"0 39.999840 116.325001\n",
"5 40.000565 116.324806"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.iloc[0:5, 0:2]"
]
},
{
"cell_type": "markdown",
"id": "0a6f17f8-8dff-4def-bb32-79c2600e8e66",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}