refactoring
This commit is contained in:
@@ -75,8 +75,19 @@
|
||||
" dataFrame_kreise = pd.merge(dataFrame, self.kreise, how = 'left', left_on = 'gemeindeschluessel', right_index = True)\n",
|
||||
" dataFrame['Kreis'] = dataFrame_kreise[3]\n",
|
||||
" dataFrame['Einwohnerzahl'] = dataFrame_kreise[6]\n",
|
||||
" dataFrame['Bundesland'] = dataFrame['bundesland'].map(lambda bundesland: self.kreise.loc[bundesland, '2'])\n",
|
||||
" return dataFrame"
|
||||
" return self._addBundeslandColumn(dataFrame)\n",
|
||||
" \n",
|
||||
" def _addBundeslandColumn(self, dataFrame):\n",
|
||||
" return pd.merge(\n",
|
||||
" dataFrame,\n",
|
||||
" self._createBundeslandByKeyTable(),\n",
|
||||
" how = 'left',\n",
|
||||
" left_on = 'bundesland',\n",
|
||||
" right_index = True)\n",
|
||||
"\n",
|
||||
" def _createBundeslandByKeyTable(self):\n",
|
||||
" bundeslandByKeyTable = self.kreise.reset_index().rename(columns = {1: 'Key', '2': 'Bundesland'})[['Key', 'Bundesland']]\n",
|
||||
" return bundeslandByKeyTable[bundeslandByKeyTable['Key'].str.len() == 2].set_index('Key')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user