File size: 3,319 Bytes
3ae82b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NYC Yellow Taxi 2017-10 데이터 탐색"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_parquet('yellow_tripdata_2017-10.parquet')\n",
    "print(f'총 {len(df):,}건, {len(df.columns)}개 컬럼')\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Zone Lookup 매핑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "zones = pd.read_csv('taxi+_zone_lookup.csv')\n",
    "zones.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 픽업/드롭오프에 Zone 이름 붙이기\n",
    "df_named = df.merge(zones[['LocationID','Borough','Zone']], left_on='PULocationID', right_on='LocationID', how='left')\n",
    "df_named = df_named.rename(columns={'Borough': 'PU_Borough', 'Zone': 'PU_Zone'}).drop(columns='LocationID')\n",
    "df_named = df_named.merge(zones[['LocationID','Borough','Zone']], left_on='DOLocationID', right_on='LocationID', how='left')\n",
    "df_named = df_named.rename(columns={'Borough': 'DO_Borough', 'Zone': 'DO_Zone'}).drop(columns='LocationID')\n",
    "\n",
    "df_named[['tpep_pickup_datetime','PU_Borough','PU_Zone','DO_Borough','DO_Zone','trip_distance','total_amount']].head(20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 기본 분포"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 픽업 많은 Zone Top 15\n",
    "top_pu = df_named['PU_Zone'].value_counts().head(15)\n",
    "print('=== 픽업 Top 15 ===')\n",
    "print(top_pu)\n",
    "print()\n",
    "\n",
    "# 자치구별 건수\n",
    "print('=== 자치구별 픽업 ===')\n",
    "print(df_named['PU_Borough'].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 시간대별 수요\n",
    "df['hour'] = df['tpep_pickup_datetime'].dt.hour\n",
    "hourly = df['hour'].value_counts().sort_index()\n",
    "hourly.plot(kind='bar', figsize=(12,4), title='시간대별 픽업 건수')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 거리 & 요금 분포 (이상치 제거)\n",
    "reasonable = df[(df['trip_distance'] > 0) & (df['trip_distance'] < 30) & (df['total_amount'] > 0) & (df['total_amount'] < 100)]\n",
    "reasonable[['trip_distance','total_amount']].hist(bins=50, figsize=(12,4))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}