{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Examples**"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" angles | \n",
" degrees | \n",
"
\n",
" \n",
" \n",
" \n",
" circle | \n",
" 0 | \n",
" 360 | \n",
"
\n",
" \n",
" right triangle | \n",
" 3 | \n",
" 180 | \n",
"
\n",
" \n",
" rhombus | \n",
" 4 | \n",
" 360 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" angles degrees\n",
"circle 0 360\n",
"right triangle 3 180\n",
"rhombus 4 360"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame({'angles': [0, 3, 4],\n",
" 'degrees': [360, 180, 360]},\n",
" index=['circle', 'right triangle', 'rhombus'])\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Multiply a DataFrame of different shape with operator version:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" angles | \n",
"
\n",
" \n",
" \n",
" \n",
" circle | \n",
" 0 | \n",
"
\n",
" \n",
" right triangle | \n",
" 3 | \n",
"
\n",
" \n",
" rhombus | \n",
" 4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" angles\n",
"circle 0\n",
"right triangle 3\n",
"rhombus 4"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"other = pd.DataFrame({'angles': [0, 3, 4]},\n",
" index=['circle', 'right triangle', 'rhombus'])\n",
"other"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" angles | \n",
" degrees | \n",
"
\n",
" \n",
" \n",
" \n",
" circle | \n",
" 0 | \n",
" NaN | \n",
"
\n",
" \n",
" right triangle | \n",
" 9 | \n",
" NaN | \n",
"
\n",
" \n",
" rhombus | \n",
" 16 | \n",
" NaN | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" angles degrees\n",
"circle 0 NaN\n",
"right triangle 9 NaN\n",
"rhombus 16 NaN"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df * other"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" angles | \n",
" degrees | \n",
"
\n",
" \n",
" \n",
" \n",
" circle | \n",
" 0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" right triangle | \n",
" 9 | \n",
" 0.0 | \n",
"
\n",
" \n",
" rhombus | \n",
" 16 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" angles degrees\n",
"circle 0 0.0\n",
"right triangle 9 0.0\n",
"rhombus 16 0.0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.mul(other, fill_value=0)"
]
}
],
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}