Add code for some of the examples used in the ppt

101_preparation
Tim Skov Jacobsen 2019-11-10 20:02:41 +01:00
parent 61d83feb16
commit cc7c677465
3 changed files with 2482 additions and 0 deletions

View File

@ -0,0 +1,803 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from IPython.core.display import HTML\n",
"\n",
"def display_dataframes(table_list):\n",
" return HTML('<table><tr style=\"background-color:white;\">' + \n",
" ''.join(['<td>' + table._repr_html_() + '</td>' for table in table_list]) + \n",
" '</tr></table>'\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dataframe of rows that changed between two other dataframes"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"code_folding": [
1,
12,
23,
34
],
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"<table><tr style=\"background-color:white;\"><td><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>Type</th>\n",
" <th>Profile</th>\n",
" <th>Force[kN]</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>S1-12-106665</th>\n",
" <td>P04</td>\n",
" <td>HE200A</td>\n",
" <td>8.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106668</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>16.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106673</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106678</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>12.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106683</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>7.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106685</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>3.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106686</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>3.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106687</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>3.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106688</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>6.9</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div></td><td><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>Type</th>\n",
" <th>Profile</th>\n",
" <th>Force[kN]</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>S1-12-106665</th>\n",
" <td>P04</td>\n",
" <td>HE200A</td>\n",
" <td>8.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106668</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>10.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106673</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106678</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>9.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106683</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>7.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106685</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>3.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106686</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>3.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106687</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>8.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106688</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>5.2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div></td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame({\n",
" 'ID': [\n",
" 'S1-12-106665', \n",
" 'S1-12-106668', \n",
" 'S1-12-106673', \n",
" 'S1-12-106678', \n",
" 'S1-12-106683', \n",
" 'S1-12-106685',\n",
" 'S1-12-106686',\n",
" 'S1-12-106687',\n",
" 'S1-12-106688',\n",
" ],\n",
" 'Type': [\n",
" 'P04',\n",
" 'P01',\n",
" 'P01',\n",
" 'P01',\n",
" 'P03',\n",
" 'P03',\n",
" 'P03',\n",
" 'P03',\n",
" 'P03',\n",
" ],\n",
" 'Profile': [\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" 'HE200A',\n",
" ],\n",
" 'Force[kN]': [\n",
" 8.2,\n",
" 16.7,\n",
" 16.0,\n",
" 12.5,\n",
" 7.6,\n",
" 3.9,\n",
" 3.1,\n",
" 3.1,\n",
" 6.9,\n",
"\n",
" ]\n",
"})\n",
"df1 = df.set_index('ID')\n",
"\n",
"# Copy dataframe and change some values\n",
"df2 = df1.copy()\n",
"df2.at['S1-12-106668', 'Force[kN]'] = 10.4\n",
"df2.at['S1-12-106678', 'Force[kN]'] = 9.7\n",
"df2.at['S1-12-106687', 'Force[kN]'] = 8.1\n",
"df2.at['S1-12-106688', 'Force[kN]'] = 5.2\n",
"\n",
"\n",
"\n",
"display_dataframes([df1, df2])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>Type</th>\n",
" <th>Profile</th>\n",
" <th>Force[kN]</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>S1-12-106668</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>10.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106678</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>9.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106687</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>8.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106688</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>5.2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Type Profile Force[kN]\n",
"ID \n",
"S1-12-106668 P01 HE200A 10.4\n",
"S1-12-106678 P01 HE200A 9.7\n",
"S1-12-106687 P03 HE200A 8.1\n",
"S1-12-106688 P03 HE200A 5.2"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create dataframe of rows where pile force \n",
"# changed from df1 to df2 \n",
"df3 = df2[df1['Force[kN]'] != df2['Force[kN]']]\n",
"df3"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>Type</th>\n",
" <th>Profile</th>\n",
" <th>New_Force[kN]</th>\n",
" <th>Old_Force[kN]</th>\n",
" <th>% change</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>S1-12-106668</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>10.4</td>\n",
" <td>16.7</td>\n",
" <td>-6.93</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106678</th>\n",
" <td>P01</td>\n",
" <td>HE200A</td>\n",
" <td>9.7</td>\n",
" <td>12.5</td>\n",
" <td>-3.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106687</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>8.1</td>\n",
" <td>3.1</td>\n",
" <td>5.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>S1-12-106688</th>\n",
" <td>P03</td>\n",
" <td>HE200A</td>\n",
" <td>5.2</td>\n",
" <td>6.9</td>\n",
" <td>-1.87</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Type Profile New_Force[kN] Old_Force[kN] % change\n",
"ID \n",
"S1-12-106668 P01 HE200A 10.4 16.7 -6.93\n",
"S1-12-106678 P01 HE200A 9.7 12.5 -3.08\n",
"S1-12-106687 P03 HE200A 8.1 3.1 5.50\n",
"S1-12-106688 P03 HE200A 5.2 6.9 -1.87"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Rename column with new pile forces \n",
"df3 = df3.rename(columns={'Force[kN]': 'New_Force[kN]'})\n",
"\n",
"# Insert column with old pile force\n",
"df3 = df3.merge(df1[['Force[kN]']], on='ID', how='inner')\n",
"\n",
"# Rename column with old pile force\n",
"df3 = df3.rename(columns={'Force[kN]': 'Old_Force[kN]'})\n",
"\n",
"# Rearrange columns so column with new pile force is rightmost\n",
"# df3 = df3[['Type', 'Profile', 'Old_Force[kN]', 'New_Force[kN]']]\n",
" \n",
"# Add column with percentage change in pile force\n",
"df3['% change'] = 1.1 * (df3['New_Force[kN]'] - df3['Old_Force[kN]'])\n",
"\n",
"df3"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def color_neg_pos(val):\n",
" return f\"color: {'red' if val < 0 else 'blue'}\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style type=\"text/css\" >\n",
" #T_178fc528_03ec_11ea_a501_2816a853165frow0_col4 {\n",
" color: red;\n",
" } #T_178fc528_03ec_11ea_a501_2816a853165frow1_col4 {\n",
" color: red;\n",
" } #T_178fc528_03ec_11ea_a501_2816a853165frow2_col4 {\n",
" color: blue;\n",
" } #T_178fc528_03ec_11ea_a501_2816a853165frow3_col4 {\n",
" color: red;\n",
" }</style><table id=\"T_178fc528_03ec_11ea_a501_2816a853165f\" ><thead> <tr> <th class=\"blank level0\" ></th> <th class=\"col_heading level0 col0\" >Type</th> <th class=\"col_heading level0 col1\" >Profile</th> <th class=\"col_heading level0 col2\" >New_Force[kN]</th> <th class=\"col_heading level0 col3\" >Old_Force[kN]</th> <th class=\"col_heading level0 col4\" >% change</th> </tr> <tr> <th class=\"index_name level0\" >ID</th> <th class=\"blank\" ></th> <th class=\"blank\" ></th> <th class=\"blank\" ></th> <th class=\"blank\" ></th> <th class=\"blank\" ></th> </tr></thead><tbody>\n",
" <tr>\n",
" <th id=\"T_178fc528_03ec_11ea_a501_2816a853165flevel0_row0\" class=\"row_heading level0 row0\" >S1-12-106668</th>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow0_col0\" class=\"data row0 col0\" >P01</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow0_col1\" class=\"data row0 col1\" >HE200A</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow0_col2\" class=\"data row0 col2\" >10.4</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow0_col3\" class=\"data row0 col3\" >16.7</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow0_col4\" class=\"data row0 col4\" >-6.93</td>\n",
" </tr>\n",
" <tr>\n",
" <th id=\"T_178fc528_03ec_11ea_a501_2816a853165flevel0_row1\" class=\"row_heading level0 row1\" >S1-12-106678</th>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow1_col0\" class=\"data row1 col0\" >P01</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow1_col1\" class=\"data row1 col1\" >HE200A</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow1_col2\" class=\"data row1 col2\" >9.7</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow1_col3\" class=\"data row1 col3\" >12.5</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow1_col4\" class=\"data row1 col4\" >-3.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th id=\"T_178fc528_03ec_11ea_a501_2816a853165flevel0_row2\" class=\"row_heading level0 row2\" >S1-12-106687</th>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow2_col0\" class=\"data row2 col0\" >P03</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow2_col1\" class=\"data row2 col1\" >HE200A</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow2_col2\" class=\"data row2 col2\" >8.1</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow2_col3\" class=\"data row2 col3\" >3.1</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow2_col4\" class=\"data row2 col4\" >5.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th id=\"T_178fc528_03ec_11ea_a501_2816a853165flevel0_row3\" class=\"row_heading level0 row3\" >S1-12-106688</th>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow3_col0\" class=\"data row3 col0\" >P03</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow3_col1\" class=\"data row3 col1\" >HE200A</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow3_col2\" class=\"data row3 col2\" >5.2</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow3_col3\" class=\"data row3 col3\" >6.9</td>\n",
" <td id=\"T_178fc528_03ec_11ea_a501_2816a853165frow3_col4\" class=\"data row3 col4\" >-1.87</td>\n",
" </tr>\n",
" </tbody></table>"
],
"text/plain": [
"<pandas.io.formats.style.Styler at 0x24e7fa65e80>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Color changes\n",
"df3.style.applymap(color_neg_pos, subset=['% change'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Customized merging of dataframes "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><tr style=\"background-color:white;\"><td><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>Invoice</th>\n",
" <th>Currency</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20561</td>\n",
" <td>EUR</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>20562</td>\n",
" <td>EUR</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>20563</td>\n",
" <td>EUR</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>20564</td>\n",
" <td>USD</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div></td><td><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>Ref</th>\n",
" <th>Amount</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20561</td>\n",
" <td>150</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>INV20562</td>\n",
" <td>175</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>INV20563BG</td>\n",
" <td>160</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>20564</td>\n",
" <td>180</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div></td><td><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>Invoice</th>\n",
" <th>Currency</th>\n",
" <th>Amount</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>20561</td>\n",
" <td>EUR</td>\n",
" <td>150</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>20562</td>\n",
" <td>EUR</td>\n",
" <td>175</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>20563</td>\n",
" <td>EUR</td>\n",
" <td>160</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>20564</td>\n",
" <td>USD</td>\n",
" <td>180</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div></td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"df1 = pd.DataFrame({'Invoice': ['20561', '20562', '20563', '20564'],\n",
" 'Currency': ['EUR', 'EUR', 'EUR', 'USD']})\n",
"df2 = pd.DataFrame({'Ref': ['20561', 'INV20562', 'INV20563BG', '20564'],\n",
" 'Amount': ['150', '175', '160', '180'],})\n",
"\n",
"df3 = df2.copy()\n",
"df3['Invoice'] = [val for idx, val in enumerate(df1['Invoice']) if val in df2['Ref'][idx]]\n",
"df3 = df1.merge(df3[['Amount', 'Invoice']], on='Invoice')\n",
"\n",
"display_dataframes([df1, df2, df3])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first two dataframes are merged on Invoice/Ref column. The comparison checks if the Invoice number is contained in the Ref number. Other characters than the match are allowed to be in the string."
]
}
],
"metadata": {
"hide_input": false,
"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"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Table of Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long