{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1\n",
"Import NumPy under the alias `np`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2\n",
"Import pandas under the alias `pd`."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 3\n",
"Given the DataFrame `data`, remove all of its rows that contain null values using the pandas method discussed in the lesson."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"data = pd.DataFrame(np.array([[np.nan, 8, 12],[np.nan, 16, np.nan],[4, 13, 45]]))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
" \n",
" \n",
" 2 | \n",
" 4.0 | \n",
" 13.0 | \n",
" 45.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2\n",
"2 4.0 13.0 45.0"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Solution goes here\n",
"data.dropna()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 4\n",
"Given the DataFrame `data`, remove all of its columns that contain null values using the pandas method discussed in the lesson."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 1 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 8.0 | \n",
"
\n",
" \n",
" 1 | \n",
" 16.0 | \n",
"
\n",
" \n",
" 2 | \n",
" 13.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 1\n",
"0 8.0\n",
"1 16.0\n",
"2 13.0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Solution goes here\n",
"data.dropna(axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 5\n",
"Given the DataFrame `data`, replace all of its null values with `💩` (copy and paste it)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 💩 | \n",
" 8.0 | \n",
" 12 | \n",
"
\n",
" \n",
" 1 | \n",
" 💩 | \n",
" 16.0 | \n",
" 💩 | \n",
"
\n",
" \n",
" 2 | \n",
" 4 | \n",
" 13.0 | \n",
" 45 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2\n",
"0 💩 8.0 12\n",
"1 💩 16.0 💩\n",
"2 4 13.0 45"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.fillna('💩')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 6\n",
"Given the DataFrame `data`, replace all of its null values with the mean value across the entire DataFrame."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 4.0 | \n",
" 8.0 | \n",
" 12.0 | \n",
"
\n",
" \n",
" 1 | \n",
" 4.0 | \n",
" 16.0 | \n",
" 28.5 | \n",
"
\n",
" \n",
" 2 | \n",
" 4.0 | \n",
" 13.0 | \n",
" 45.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0 1 2\n",
"0 4.0 8.0 12.0\n",
"1 4.0 16.0 28.5\n",
"2 4.0 13.0 45.0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.fillna(data.mean())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}