Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd, numpy as np\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 30,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" char hp power\n",
"5 Elf 150.0 101\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"3 Davemon 204.9 101\n",
"9 Dw@rfff 220.0 105"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"raw_data = [\n",
" ('Elf', 150, 101),\n",
" ('Human', 200, 75),\n",
" ('Mark', 205, 100),\n",
" ('Davemon', 204.9, 101),\n",
" ('Dw@rfff', 220, 105)\n",
"]\n",
"\n",
"df = pd.DataFrame(\n",
" raw_data, \n",
" columns=['char', 'hp', 'power']\n",
")\n",
"df.index = [5,6,8,3,9]\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Review: Slicing!!!"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 5 entries, 0 to 4\n",
"Data columns (total 3 columns):\n",
"char 5 non-null object\n",
"hp 5 non-null float64\n",
"power 5 non-null int64\n",
"dtypes: float64(1), int64(1), object(1)\n",
"memory usage: 200.0+ bytes\n"
]
}
],
"source": [
"# whats the type?\n",
"# df.hp.dtype\n",
"# df.dtypes\n",
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" char hp power\n",
"0 Elf 150.0 101\n",
"1 Human 200.0 75\n",
"2 Mark 205.0 100\n",
"3 Davemon 204.9 101\n",
"4 Dw@rfff 220.0 105"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# bonus: all of HP, except the last item\n",
"\n",
"df.iloc[2, 2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"df.loc[row_index, column_index]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[2, 'power']"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"power 100\n",
"hp 205\n",
"Name: 2, dtype: object"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[2, ['power', 'hp']]"
]
},
{
"cell_type": "code",
"execution_count": 26,
"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>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" hp power\n",
"3 204.9 101\n",
"4 220.0 105"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[[3,4],[1, 2]]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"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>power</th>\n",
" <th>hp</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>101</td>\n",
" <td>150.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>75</td>\n",
" <td>200.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>100</td>\n",
" <td>205.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>101</td>\n",
" <td>204.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>105</td>\n",
" <td>220.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" power hp\n",
"0 101 150.0\n",
"1 75 200.0\n",
"2 100 205.0\n",
"3 101 204.9\n",
"4 105 220.0"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[['power', 'hp']]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"df_500 = df.sample(n=500, replace=True)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>110 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" char hp power\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
".. ... ... ...\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"\n",
"[110 rows x 3 columns]"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_500[df_500['char'] == \"Mark\"]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"357"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eval(\"123 + 234\")"
]
},
{
"cell_type": "code",
"execution_count": 48,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" char hp power\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_500.query(\"char == \\\"Mark\\\"\").head()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"This is string and they are pretty cool\", said the teapot\n"
]
}
],
"source": [
"print(\"\\\"This is string and they are pretty cool\\\", said the teapot\")"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"This is astring....\", siad the teabpot\n"
]
}
],
"source": [
"print('\"This is astring....\", siad the teabpot',)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Human</td>\n",
" <td>200.0</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>101</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>500 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" char hp power\n",
"9 Dw@rfff 220.0 105\n",
"3 Davemon 204.9 101\n",
"3 Davemon 204.9 101\n",
"9 Dw@rfff 220.0 105\n",
"8 Mark 205.0 100\n",
"5 Elf 150.0 101\n",
"8 Mark 205.0 100\n",
"9 Dw@rfff 220.0 105\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"6 Human 200.0 75\n",
"5 Elf 150.0 101\n",
"9 Dw@rfff 220.0 105\n",
"9 Dw@rfff 220.0 105\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"9 Dw@rfff 220.0 105\n",
"8 Mark 205.0 100\n",
"3 Davemon 204.9 101\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"5 Elf 150.0 101\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"5 Elf 150.0 101\n",
"3 Davemon 204.9 101\n",
"9 Dw@rfff 220.0 105\n",
"9 Dw@rfff 220.0 105\n",
"6 Human 200.0 75\n",
".. ... ... ...\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"9 Dw@rfff 220.0 105\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"3 Davemon 204.9 101\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"8 Mark 205.0 100\n",
"9 Dw@rfff 220.0 105\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"3 Davemon 204.9 101\n",
"5 Elf 150.0 101\n",
"5 Elf 150.0 101\n",
"5 Elf 150.0 101\n",
"9 Dw@rfff 220.0 105\n",
"6 Human 200.0 75\n",
"6 Human 200.0 75\n",
"3 Davemon 204.9 101\n",
"5 Elf 150.0 101\n",
"6 Human 200.0 75\n",
"6 Human 200.0 75\n",
"8 Mark 205.0 100\n",
"6 Human 200.0 75\n",
"5 Elf 150.0 101\n",
"\n",
"[500 rows x 3 columns]"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_500"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100000009"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def add_one(num):\n",
" return num + 100000000\n",
"\n",
"add_one(9)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add_one = lambda num: num + 1\n",
"add_one(9)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9 105\n",
"3 101\n",
"3 101\n",
"9 105\n",
"8 100\n",
"Name: power, dtype: int64"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_500['power'].head()"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
"df_500['power'] = df_500['power'].map(lambda num: num * 3456)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"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>index</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>470</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>471</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>472</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>473</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>474</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>475</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>476</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>477</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>478</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>479</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>480</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>481</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>482</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>483</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>484</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>485</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>486</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>487</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>488</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>489</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>490</th>\n",
" <td>9</td>\n",
" <td>220000.0</td>\n",
" <td>362880000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>491</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>492</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>493</th>\n",
" <td>3</td>\n",
" <td>204900.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>494</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>495</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>496</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>497</th>\n",
" <td>8</td>\n",
" <td>205000.0</td>\n",
" <td>345600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>498</th>\n",
" <td>6</td>\n",
" <td>200000.0</td>\n",
" <td>259200000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>499</th>\n",
" <td>5</td>\n",
" <td>150000.0</td>\n",
" <td>349056000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>500 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" index hp power\n",
"0 9 220000.0 362880000\n",
"1 3 204900.0 349056000\n",
"2 3 204900.0 349056000\n",
"3 9 220000.0 362880000\n",
"4 8 205000.0 345600000\n",
"5 5 150000.0 349056000\n",
"6 8 205000.0 345600000\n",
"7 9 220000.0 362880000\n",
"8 6 200000.0 259200000\n",
"9 8 205000.0 345600000\n",
"10 6 200000.0 259200000\n",
"11 5 150000.0 349056000\n",
"12 9 220000.0 362880000\n",
"13 9 220000.0 362880000\n",
"14 8 205000.0 345600000\n",
"15 8 205000.0 345600000\n",
"16 8 205000.0 345600000\n",
"17 9 220000.0 362880000\n",
"18 8 205000.0 345600000\n",
"19 3 204900.0 349056000\n",
"20 8 205000.0 345600000\n",
"21 8 205000.0 345600000\n",
"22 5 150000.0 349056000\n",
"23 6 200000.0 259200000\n",
"24 8 205000.0 345600000\n",
"25 5 150000.0 349056000\n",
"26 3 204900.0 349056000\n",
"27 9 220000.0 362880000\n",
"28 9 220000.0 362880000\n",
"29 6 200000.0 259200000\n",
".. ... ... ...\n",
"470 6 200000.0 259200000\n",
"471 8 205000.0 345600000\n",
"472 8 205000.0 345600000\n",
"473 8 205000.0 345600000\n",
"474 8 205000.0 345600000\n",
"475 8 205000.0 345600000\n",
"476 9 220000.0 362880000\n",
"477 8 205000.0 345600000\n",
"478 8 205000.0 345600000\n",
"479 3 204900.0 349056000\n",
"480 6 200000.0 259200000\n",
"481 8 205000.0 345600000\n",
"482 8 205000.0 345600000\n",
"483 9 220000.0 362880000\n",
"484 6 200000.0 259200000\n",
"485 8 205000.0 345600000\n",
"486 3 204900.0 349056000\n",
"487 5 150000.0 349056000\n",
"488 5 150000.0 349056000\n",
"489 5 150000.0 349056000\n",
"490 9 220000.0 362880000\n",
"491 6 200000.0 259200000\n",
"492 6 200000.0 259200000\n",
"493 3 204900.0 349056000\n",
"494 5 150000.0 349056000\n",
"495 6 200000.0 259200000\n",
"496 6 200000.0 259200000\n",
"497 8 205000.0 345600000\n",
"498 6 200000.0 259200000\n",
"499 5 150000.0 349056000\n",
"\n",
"[500 rows x 3 columns]"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def scale_column(column):\n",
" scaled_column = column * 1000\n",
" return scaled_column\n",
"\n",
"df_500[['hp', 'power']].apply(scale_column).reset_index()"
]
},
{
"cell_type": "code",
"execution_count": 82,
"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>char</th>\n",
" <th>hp</th>\n",
" <th>power</th>\n",
" <th>is_300k</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Dw@rfff</td>\n",
" <td>220.0</td>\n",
" <td>362880</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Davemon</td>\n",
" <td>204.9</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Mark</td>\n",
" <td>205.0</td>\n",
" <td>345600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Elf</td>\n",
" <td>150.0</td>\n",
" <td>349056</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>403 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" char hp power is_300k\n",
"9 Dw@rfff 220.0 362880 1\n",
"3 Davemon 204.9 349056 1\n",
"3 Davemon 204.9 349056 1\n",
"9 Dw@rfff 220.0 362880 1\n",
"8 Mark 205.0 345600 1\n",
"5 Elf 150.0 349056 1\n",
"8 Mark 205.0 345600 1\n",
"9 Dw@rfff 220.0 362880 1\n",
"8 Mark 205.0 345600 1\n",
"5 Elf 150.0 349056 1\n",
"9 Dw@rfff 220.0 362880 1\n",
"9 Dw@rfff 220.0 362880 1\n",
"8 Mark 205.0 345600 1\n",
"8