File name
Commit message
Commit date
File name
Commit message
Commit date
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1d73f8cb",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "ee66e1a7",
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame([['환자 코드', '연령', '성별', '거주지'],\n",
" ['A00301', 23, '남', '서울시'],\n",
" ['B00809', 53, '여', '제주도']])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "a85434e1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>환자 코드</td>\n",
" <td>연령</td>\n",
" <td>성별</td>\n",
" <td>거주지</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>A00301</td>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>B00809</td>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3\n",
"0 환자 코드 연령 성별 거주지\n",
"1 A00301 23 남 서울시\n",
"2 B00809 53 여 제주도"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "efd1aa89",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 환자 코드\n",
"1 A00301\n",
"2 B00809\n",
"Name: 0, dtype: object"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[0]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "85b33d0a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>거주지</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 3\n",
"0 거주지\n",
"1 서울시\n",
"2 제주도"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[[3]]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ae89ed0b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>연령</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>53</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 1\n",
"0 연령\n",
"1 23\n",
"2 53"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[[1]]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "04962a56",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.series.Series"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(df[1])"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "a4db8d44",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.frame.DataFrame"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(df[[1]])"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "5b384bf6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 환자 코드\n",
"1 연령\n",
"2 성별\n",
"3 거주지\n",
"Name: 0, dtype: object"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[0]"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "72348fc7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 A00301\n",
"1 23\n",
"2 남\n",
"3 서울시\n",
"Name: 1, dtype: object"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[1]"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "cda15c56",
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame([['환자 코드', '연령', '성별', '거주지'],\n",
" ['A00301', 23, '남', '서울시'],\n",
" ['B00809', 53, '여', '제주도']],\n",
" index = ['구분', 'A00301', 'B00809'])"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "329fafc4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>구분</th>\n",
" <td>환자 코드</td>\n",
" <td>연령</td>\n",
" <td>성별</td>\n",
" <td>거주지</td>\n",
" </tr>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>A00301</td>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B00809</th>\n",
" <td>B00809</td>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3\n",
"구분 환자 코드 연령 성별 거주지\n",
"A00301 A00301 23 남 서울시\n",
"B00809 B00809 53 여 제주도"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "833e3041",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>A00301</td>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3\n",
"A00301 A00301 23 남 서울시"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[['A00301']]"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "8671a23d",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>A00301</td>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B00809</th>\n",
" <td>B00809</td>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3\n",
"A00301 A00301 23 남 서울시\n",
"B00809 B00809 53 여 제주도"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[[1, 2]]"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "58c50e7b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>구분</th>\n",
" <td>환자 코드</td>\n",
" <td>연령</td>\n",
" <td>성별</td>\n",
" <td>거주지</td>\n",
" </tr>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>A00301</td>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B00809</th>\n",
" <td>B00809</td>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3\n",
"구분 환자 코드 연령 성별 거주지\n",
"A00301 A00301 23 남 서울시\n",
"B00809 B00809 53 여 제주도"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "c3ad0a58",
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame([[23, '남', '서울시'],\n",
" [53, '여', '제주도']],\n",
" index = ['A00301', 'B00809'], \n",
" columns = ['연령', '성별', '거주지'])"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "3020cfc9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>연령</th>\n",
" <th>성별</th>\n",
" <th>거주지</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B00809</th>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 연령 성별 거주지\n",
"A00301 23 남 서울시\n",
"B00809 53 여 제주도"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "af7b63cd",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"연령 23\n",
"성별 남\n",
"거주지 서울시\n",
"Name: A00301, dtype: object"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc['A00301']"
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "8b30c291",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"./sample.csv\", encoding='euc-kr', index_col='환자코드')"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "81b4bf0f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>연령</th>\n",
" <th>성별</th>\n",
" <th>거주지</th>\n",
" </tr>\n",
" <tr>\n",
" <th>환자코드</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>A00301</th>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B00809</th>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 연령 성별 거주지\n",
"환자코드 \n",
"A00301 23 남 서울시\n",
"B00809 53 여 제주도"
]
},
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "db6540c0",
"metadata": {},
"outputs": [],
"source": [
"df.rename(index={'A00301':'환자1', 'B00809':'환자2'}, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 106,
"id": "4d0eaed3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>연령</th>\n",
" <th>성별</th>\n",
" <th>거주지</th>\n",
" </tr>\n",
" <tr>\n",
" <th>환자코드</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>환자1</th>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>환자2</th>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 연령 성별 거주지\n",
"환자코드 \n",
"환자1 23 남 서울시\n",
"환자2 53 여 제주도"
]
},
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "ed6d5292",
"metadata": {},
"outputs": [],
"source": [
"df.rename(columns={'연령':'Age', '성별':'Sex', '거주지':'Addr'}, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "d8f2005e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Sex</th>\n",
" <th>Addr</th>\n",
" </tr>\n",
" <tr>\n",
" <th>환자코드</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>환자1</th>\n",
" <td>23</td>\n",
" <td>남</td>\n",
" <td>서울시</td>\n",
" </tr>\n",
" <tr>\n",
" <th>환자2</th>\n",
" <td>53</td>\n",
" <td>여</td>\n",
" <td>제주도</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Sex Addr\n",
"환자코드 \n",
"환자1 23 남 서울시\n",
"환자2 53 여 제주도"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b391deb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "80ce37bf",
"metadata": {},
"outputs": [],
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}