From f99e26731bde7ec4e904140efff85df94862a16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Wersd=C3=B6rfer?= Date: Thu, 19 Oct 2023 21:33:03 +0200 Subject: [PATCH] #1 changes --- notebooks/numpy_pandas/pandas.ipynb | 239 ++++++++++++++++++---------- 1 file changed, 151 insertions(+), 88 deletions(-) diff --git a/notebooks/numpy_pandas/pandas.ipynb b/notebooks/numpy_pandas/pandas.ipynb index cc29f2e..22b930d 100644 --- a/notebooks/numpy_pandas/pandas.ipynb +++ b/notebooks/numpy_pandas/pandas.ipynb @@ -3,7 +3,9 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "%config InlineBackend.figure_format = 'retina'" @@ -32,7 +34,9 @@ { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import numpy as np\n", @@ -41,7 +45,7 @@ "\n", "import matplotlib.pyplot as plt\n", "\n", - "pd.set_option('max_columns', 50)\n", + "pd.options.display.max_columns = 50\n", "%matplotlib inline" ] }, @@ -57,7 +61,9 @@ { "cell_type": "code", "execution_count": 3, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "values = [3, \"foo\", 3.14, 42, -23, \"bar\"]" @@ -66,7 +72,9 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "s = pd.Series(values)" @@ -75,7 +83,9 @@ { "cell_type": "code", "execution_count": 5, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "name": "stdout", @@ -98,7 +108,9 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -118,7 +130,9 @@ { "cell_type": "code", "execution_count": 7, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "index = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]" @@ -127,7 +141,9 @@ { "cell_type": "code", "execution_count": 8, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "s = pd.Series(values, index=index)" @@ -136,7 +152,9 @@ { "cell_type": "code", "execution_count": 9, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -162,7 +180,9 @@ { "cell_type": "code", "execution_count": 10, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -182,7 +202,9 @@ { "cell_type": "code", "execution_count": 11, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -205,7 +227,9 @@ { "cell_type": "code", "execution_count": 12, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -238,8 +262,10 @@ }, { "cell_type": "code", - "execution_count": 74, - "metadata": {}, + "execution_count": 13, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "cities_url = \"https://de.wikipedia.org/wiki/Liste_der_gr%C3%B6%C3%9Ften_St%C3%A4dte_Europas\"\n", @@ -248,8 +274,10 @@ }, { "cell_type": "code", - "execution_count": 75, - "metadata": {}, + "execution_count": 14, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "df = tables[0]" @@ -257,8 +285,10 @@ }, { "cell_type": "code", - "execution_count": 76, - "metadata": {}, + "execution_count": 15, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -281,11 +311,11 @@ " \n", " \n", " \n", - " Rang\n", + " Unnamed: 0\n", " Name\n", - " Einwohner\n", - " Stand\n", " Staat\n", + " Ein­wohner\n", + " Stand\n", " Quelle\n", " Panorama\n", " \n", @@ -295,73 +325,73 @@ " 0\n", " 1\n", " Istanbul\n", - " 14.804.116\n", - " 31. Jan. 2017\n", - " Türkei\n", - " TÜİK[2]\n", - " Istanbul (9.301.455 Einw., 2.767 Einw./km²); m...\n", + " Türkei[1]\n", + " 15.907.951 [2]\n", + " 31. Dez. 2022\n", + " TÜİK[3]\n", + " NaN\n", " \n", " \n", " 1\n", " 2\n", " Moskau\n", - " 12.228.685\n", - " 01. Juli 2017\n", - " Russland\n", - " RAS[3]\n", - " Moskau (12.054.243 Einw., 4.802 Einw./km²)\n", + " Russland[1]\n", + " 12.455.682\n", + " 1. Jan. 2021\n", + " Rosstat[4]\n", + " NaN\n", " \n", " \n", " 2\n", " 3\n", " London\n", - " 8.825.001\n", - " 30. Juni 2017\n", " Vereinigtes Königreich\n", - " ONS[4]\n", - " London (City of London 7.604 Einw., 2.925 E./k...\n", + " 8.799.900\n", + " 21. März 2021\n", + " ONS[5]\n", + " NaN\n", " \n", " \n", " 3\n", " 4\n", " Sankt Petersburg\n", - " 5.281.579\n", - " 01. Juli 2017\n", " Russland\n", - " RAS[3]\n", - " Sankt Petersburg (5.191.690 Einw., 3.628 Einw....\n", + " 5.384.342\n", + " 1. Jan. 2021\n", + " Rosstat[4]\n", + " NaN\n", " \n", " \n", " 4\n", " 5\n", " Berlin\n", - " 3.611.222\n", - " 30. Nov. 2017\n", " Deutschland\n", - " AfS[5]\n", - " Berlin (3.421.829 Einw., 3.829 Einw./km²; Aggl...\n", + " 3.755.251\n", + " 31. Dez. 2022\n", + " AfS[6]\n", + " NaN\n", " \n", " \n", "\n", "" ], "text/plain": [ - " Rang Name Einwohner Stand Staat \\\n", - "0 1 Istanbul 14.804.116 31. Jan. 2017 Türkei \n", - "1 2 Moskau 12.228.685 01. Juli 2017 Russland \n", - "2 3 London 8.825.001 30. Juni 2017 Vereinigtes Königreich \n", - "3 4 Sankt Petersburg 5.281.579 01. Juli 2017 Russland \n", - "4 5 Berlin 3.611.222 30. Nov. 2017 Deutschland \n", + " Unnamed: 0 Name Staat Ein­wohner \\\n", + "0 1 Istanbul Türkei[1] 15.907.951 [2] \n", + "1 2 Moskau Russland[1] 12.455.682 \n", + "2 3 London Vereinigtes Königreich 8.799.900 \n", + "3 4 Sankt Petersburg Russland 5.384.342 \n", + "4 5 Berlin Deutschland 3.755.251 \n", "\n", - " Quelle Panorama \n", - "0 TÜİK[2] Istanbul (9.301.455 Einw., 2.767 Einw./km²); m... \n", - "1 RAS[3] Moskau (12.054.243 Einw., 4.802 Einw./km²) \n", - "2 ONS[4] London (City of London 7.604 Einw., 2.925 E./k... \n", - "3 RAS[3] Sankt Petersburg (5.191.690 Einw., 3.628 Einw.... \n", - "4 AfS[5] Berlin (3.421.829 Einw., 3.829 Einw./km²; Aggl... " + " Stand Quelle Panorama \n", + "0 31. Dez. 2022 TÜİK[3] NaN \n", + "1 1. Jan. 2021 Rosstat[4] NaN \n", + "2 21. März 2021 ONS[5] NaN \n", + "3 1. Jan. 2021 Rosstat[4] NaN \n", + "4 31. Dez. 2022 AfS[6] NaN " ] }, - "execution_count": 76, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -372,25 +402,29 @@ }, { "cell_type": "code", - "execution_count": 77, - "metadata": {}, + "execution_count": 18, + "metadata": { + "tags": [] + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", - "RangeIndex: 101 entries, 0 to 100\n", + "RangeIndex: 103 entries, 0 to 102\n", "Data columns (total 7 columns):\n", - "Rang 101 non-null int64\n", - "Name 101 non-null object\n", - "Einwohner 101 non-null object\n", - "Stand 101 non-null object\n", - "Staat 101 non-null object\n", - "Quelle 101 non-null object\n", - "Panorama 45 non-null object\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Unnamed: 0 103 non-null int64 \n", + " 1 Name 103 non-null object\n", + " 2 Staat 103 non-null object\n", + " 3 Ein­wohner 103 non-null object\n", + " 4 Stand 103 non-null object\n", + " 5 Quelle 103 non-null object\n", + " 6 Panorama 1 non-null object\n", "dtypes: int64(1), object(6)\n", - "memory usage: 5.6+ KB\n" + "memory usage: 5.8+ KB\n" ] } ], @@ -400,24 +434,26 @@ }, { "cell_type": "code", - "execution_count": 78, - "metadata": {}, + "execution_count": 19, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { "text/plain": [ - "Index 80\n", - "Rang 808\n", - "Name 6717\n", - "Einwohner 6532\n", - "Stand 9494\n", - "Staat 7043\n", - "Quelle 6536\n", - "Panorama 7488\n", + "Index 132\n", + "Unnamed: 0 824\n", + "Name 6857\n", + "Staat 7128\n", + "Ein­wohner 6664\n", + "Stand 9617\n", + "Quelle 6821\n", + "Panorama 3323\n", "dtype: int64" ] }, - "execution_count": 78, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -435,8 +471,10 @@ }, { "cell_type": "code", - "execution_count": 79, - "metadata": {}, + "execution_count": 22, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "def time_to_datetime(df, colname):\n", @@ -444,7 +482,9 @@ " return (date_str.replace(\"\\xa0\", \"\")\n", " .replace(\"Okt\", \"Oct\")\n", " .replace(\"Dez\", \"Dec\")\n", - " .replace(\"i2\", \".2\"))\n", + " .replace(\"i2\", \".2\")\n", + " .strip()\n", + " .replace(\" \", \"\"))\n", " \n", " df[colname] = pd.to_datetime(df[colname].apply(reformat_date), format=\"%d.%b.%Y\")\n", " return df" @@ -452,9 +492,32 @@ }, { "cell_type": "code", - "execution_count": 80, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "ename": "ValueError", + "evalue": "time data \"21.März2021\" doesn't match format \"%d.%b.%Y\", at position 2. You might want to try:\n - passing `format` if your strings have a consistent format;\n - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[23], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m df \u001b[38;5;241m=\u001b[39m (df\u001b[38;5;241m.\u001b[39mrename(columns\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mstr\u001b[39m\u001b[38;5;241m.\u001b[39mlower)\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;241m.\u001b[39mpipe(time_to_datetime, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstand\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;241m.\u001b[39massign(staat\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m x: pd\u001b[38;5;241m.\u001b[39mCategorical(x[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstaat\u001b[39m\u001b[38;5;124m'\u001b[39m]),\n\u001b[1;32m 4\u001b[0m einwohner\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m x: x[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124meinwohner\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mstr\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mastype(np\u001b[38;5;241m.\u001b[39mint32),\n\u001b[1;32m 5\u001b[0m rang\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m x: x[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrang\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mastype(np\u001b[38;5;241m.\u001b[39mint8),\n\u001b[1;32m 6\u001b[0m pro_km2\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m x: x[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpanorama\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mstr\u001b[38;5;241m.\u001b[39mextract(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m(\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124md+\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124md+) E[a-z]*./km\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mastype(np\u001b[38;5;241m.\u001b[39mfloat32))\n\u001b[1;32m 7\u001b[0m \u001b[38;5;241m.\u001b[39mdrop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mquelle\u001b[39m\u001b[38;5;124m\"\u001b[39m, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;241m.\u001b[39mdrop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpanorama\u001b[39m\u001b[38;5;124m\"\u001b[39m, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m))\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/generic.py:6142\u001b[0m, in \u001b[0;36mNDFrame.pipe\u001b[0;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[1;32m 6140\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m using_copy_on_write():\n\u001b[1;32m 6141\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m common\u001b[38;5;241m.\u001b[39mpipe(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcopy(deep\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m), func, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m-> 6142\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m common\u001b[38;5;241m.\u001b[39mpipe(\u001b[38;5;28mself\u001b[39m, func, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/common.py:497\u001b[0m, in \u001b[0;36mpipe\u001b[0;34m(obj, func, *args, **kwargs)\u001b[0m\n\u001b[1;32m 495\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 496\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 497\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(obj, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "Cell \u001b[0;32mIn[22], line 10\u001b[0m, in \u001b[0;36mtime_to_datetime\u001b[0;34m(df, colname)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mreformat_date\u001b[39m(date_str):\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (date_str\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\xa0\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOkt\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOct\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDez\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDec\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mi2\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.2\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 7\u001b[0m \u001b[38;5;241m.\u001b[39mstrip()\n\u001b[1;32m 8\u001b[0m \u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m---> 10\u001b[0m df[colname] \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mto_datetime(df[colname]\u001b[38;5;241m.\u001b[39mapply(reformat_date), \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mb.\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mY\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m df\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/tools/datetimes.py:1108\u001b[0m, in \u001b[0;36mto_datetime\u001b[0;34m(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)\u001b[0m\n\u001b[1;32m 1106\u001b[0m result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39mtz_localize(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mutc\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1107\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(arg, ABCSeries):\n\u001b[0;32m-> 1108\u001b[0m cache_array \u001b[38;5;241m=\u001b[39m _maybe_cache(arg, \u001b[38;5;28mformat\u001b[39m, cache, convert_listlike)\n\u001b[1;32m 1109\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m cache_array\u001b[38;5;241m.\u001b[39mempty:\n\u001b[1;32m 1110\u001b[0m result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39mmap(cache_array)\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/tools/datetimes.py:254\u001b[0m, in \u001b[0;36m_maybe_cache\u001b[0;34m(arg, format, cache, convert_listlike)\u001b[0m\n\u001b[1;32m 252\u001b[0m unique_dates \u001b[38;5;241m=\u001b[39m unique(arg)\n\u001b[1;32m 253\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(unique_dates) \u001b[38;5;241m<\u001b[39m \u001b[38;5;28mlen\u001b[39m(arg):\n\u001b[0;32m--> 254\u001b[0m cache_dates \u001b[38;5;241m=\u001b[39m convert_listlike(unique_dates, \u001b[38;5;28mformat\u001b[39m)\n\u001b[1;32m 255\u001b[0m \u001b[38;5;66;03m# GH#45319\u001b[39;00m\n\u001b[1;32m 256\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/tools/datetimes.py:488\u001b[0m, in \u001b[0;36m_convert_listlike_datetimes\u001b[0;34m(arg, format, name, utc, unit, errors, dayfirst, yearfirst, exact)\u001b[0m\n\u001b[1;32m 486\u001b[0m \u001b[38;5;66;03m# `format` could be inferred, or user didn't ask for mixed-format parsing.\u001b[39;00m\n\u001b[1;32m 487\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmixed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 488\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _array_strptime_with_fallback(arg, name, utc, \u001b[38;5;28mformat\u001b[39m, exact, errors)\n\u001b[1;32m 490\u001b[0m result, tz_parsed \u001b[38;5;241m=\u001b[39m objects_to_datetime64ns(\n\u001b[1;32m 491\u001b[0m arg,\n\u001b[1;32m 492\u001b[0m dayfirst\u001b[38;5;241m=\u001b[39mdayfirst,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 496\u001b[0m allow_object\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 497\u001b[0m )\n\u001b[1;32m 499\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tz_parsed \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 500\u001b[0m \u001b[38;5;66;03m# We can take a shortcut since the datetime64 numpy array\u001b[39;00m\n\u001b[1;32m 501\u001b[0m \u001b[38;5;66;03m# is in UTC\u001b[39;00m\n", + "File \u001b[0;32m~/.pyenv/versions/miniconda3-latest/envs/ds_tutorial/lib/python3.11/site-packages/pandas/core/tools/datetimes.py:519\u001b[0m, in \u001b[0;36m_array_strptime_with_fallback\u001b[0;34m(arg, name, utc, fmt, exact, errors)\u001b[0m\n\u001b[1;32m 508\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_array_strptime_with_fallback\u001b[39m(\n\u001b[1;32m 509\u001b[0m arg,\n\u001b[1;32m 510\u001b[0m name,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 514\u001b[0m errors: \u001b[38;5;28mstr\u001b[39m,\n\u001b[1;32m 515\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Index:\n\u001b[1;32m 516\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 517\u001b[0m \u001b[38;5;124;03m Call array_strptime, with fallback behavior depending on 'errors'.\u001b[39;00m\n\u001b[1;32m 518\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 519\u001b[0m result, timezones \u001b[38;5;241m=\u001b[39m array_strptime(arg, fmt, exact\u001b[38;5;241m=\u001b[39mexact, errors\u001b[38;5;241m=\u001b[39merrors, utc\u001b[38;5;241m=\u001b[39mutc)\n\u001b[1;32m 520\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28many\u001b[39m(tz \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m tz \u001b[38;5;129;01min\u001b[39;00m timezones):\n\u001b[1;32m 521\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _return_parsed_timezone_results(result, timezones, utc, name)\n", + "File \u001b[0;32mstrptime.pyx:534\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mstrptime.pyx:355\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: time data \"21.März2021\" doesn't match format \"%d.%b.%Y\", at position 2. You might want to try:\n - passing `format` if your strings have a consistent format;\n - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this." + ] + } + ], "source": [ "df = (df.rename(columns=str.lower)\n", " .pipe(time_to_datetime, \"stand\")\n", @@ -2413,7 +2476,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -2427,9 +2490,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.11.5" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }