Run black on all the notebooks

- we use black's default settings
- some cells are NOT kept in black's format to:
  - increase readability
  - or show Python's flexibility with regard to style
This commit is contained in:
Alexander Hess 2024-07-15 12:07:47 +02:00
parent 0ed024e020
commit 51a5dcc8ee
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
6 changed files with 45 additions and 67 deletions

View file

@ -282,10 +282,12 @@
} }
], ],
"source": [ "source": [
"m1 = np.array([\n", "m1 = np.array(\n",
" [\n",
" [1, 2, 3, 4, 5],\n", " [1, 2, 3, 4, 5],\n",
" [6, 7, 8, 9, 10],\n", " [6, 7, 8, 9, 10],\n",
"])\n", " ]\n",
")\n",
"\n", "\n",
"m1" "m1"
] ]

View file

@ -1852,10 +1852,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[200300:200800, [\"o_street\", \"o_zip\", \"o_city\", \"o_latitude\", \"o_longitude\"]]"
" 200300:200800,\n",
" [\"o_street\", \"o_zip\", \"o_city\", \"o_latitude\", \"o_longitude\"]\n",
"]"
] ]
}, },
{ {
@ -1982,11 +1979,13 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"df = df.astype({\n", "df = df.astype(\n",
" {\n",
" \"pickup_at\": \"datetime64[ns]\",\n", " \"pickup_at\": \"datetime64[ns]\",\n",
" \"delivery_at\": \"datetime64[ns]\",\n", " \"delivery_at\": \"datetime64[ns]\",\n",
" \"cancelled\": bool,\n", " \"cancelled\": bool,\n",
"})" " }\n",
")"
] ]
}, },
{ {
@ -2686,7 +2685,7 @@
"source": [ "source": [
"df.loc[\n", "df.loc[\n",
" max_a_table,\n", " max_a_table,\n",
" [\"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"d_latitude\", \"d_longitude\"]\n", " [\"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"d_latitude\", \"d_longitude\"],\n",
"].head()" "].head()"
] ]
}, },
@ -2821,12 +2820,10 @@
" max_a_table\n", " max_a_table\n",
" &\n", " &\n",
" (\n", " (\n",
" (df[\"d_latitude\"] > 44.85)\n", " (df[\"d_latitude\"] > 44.85) | (df[\"d_longitude\"] < -0.59)\n",
" |\n",
" (df[\"d_longitude\"] < -0.59)\n",
" )\n", " )\n",
" ),\n", " ),\n",
" [\"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"d_latitude\", \"d_longitude\"]\n", " [\"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"d_latitude\", \"d_longitude\"],\n",
"].head()" "].head()"
] ]
}, },
@ -2933,12 +2930,8 @@
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[\n",
" (\n", " (max_a_table & df[\"customer_id\"].isin([6037, 79900, 80095])),\n",
" max_a_table\n", " [\"placed_at\", \"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"total\"],\n",
" &\n",
" df[\"customer_id\"].isin([6037, 79900, 80095])\n",
" ),\n",
" [\"placed_at\", \"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"total\"]\n",
"].head()" "].head()"
] ]
}, },
@ -3067,12 +3060,8 @@
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[\n",
" (\n", " (max_a_table & ~df[\"customer_id\"].isin([6037, 79900, 80095])),\n",
" max_a_table\n", " [\"placed_at\", \"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"total\"],\n",
" &\n",
" ~df[\"customer_id\"].isin([6037, 79900, 80095])\n",
" ),\n",
" [\"placed_at\", \"customer_id\", \"d_street\", \"d_zip\", \"d_city\", \"total\"]\n",
"].head()" "].head()"
] ]
}, },
@ -3166,10 +3155,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[max_a_table, \"customer_id\"].unique()"
" max_a_table,\n",
" \"customer_id\"\n",
"].unique()"
] ]
}, },
{ {
@ -3289,10 +3275,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[max_a_table, \"total\"].sum() / 100"
" max_a_table,\n",
" \"total\"\n",
"].sum() / 100"
] ]
}, },
{ {
@ -3352,10 +3335,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[max_a_table, \"total\"].min() / 100"
" max_a_table,\n",
" \"total\"\n",
"].min() / 100"
] ]
}, },
{ {
@ -3375,10 +3355,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[max_a_table, \"total\"].max() / 100"
" max_a_table,\n",
" \"total\"\n",
"].max() / 100"
] ]
}, },
{ {
@ -3438,10 +3415,7 @@
} }
], ],
"source": [ "source": [
"df.loc[\n", "df.loc[max_a_table, \"total\"].mean().round() / 100"
" max_a_table,\n",
" \"total\"\n",
"].mean().round() / 100"
] ]
} }
], ],

View file

@ -56,7 +56,7 @@
" \"orders.csv\",\n", " \"orders.csv\",\n",
" index_col=\"order_id\",\n", " index_col=\"order_id\",\n",
" dtype={\"cancelled\": bool},\n", " dtype={\"cancelled\": bool},\n",
" parse_dates=[\"placed_at\", \"pickup_at\", \"delivery_at\"]\n", " parse_dates=[\"placed_at\", \"pickup_at\", \"delivery_at\"],\n",
")" ")"
] ]
}, },

View file

@ -518,7 +518,7 @@
], ],
"source": [ "source": [
"feature_index = 2\n", "feature_index = 2\n",
"colors = ['blue', 'red', 'green']\n", "colors = [\"blue\", \"red\", \"green\"]\n",
"\n", "\n",
"for label, color in zip(range(len(iris.target_names)), colors):\n", "for label, color in zip(range(len(iris.target_names)), colors):\n",
" plt.hist(\n", " plt.hist(\n",
@ -528,7 +528,7 @@
" )\n", " )\n",
"\n", "\n",
"plt.xlabel(iris.feature_names[feature_index])\n", "plt.xlabel(iris.feature_names[feature_index])\n",
"plt.legend(loc='upper right')\n", "plt.legend(loc=\"upper right\")\n",
"plt.show()" "plt.show()"
] ]
}, },
@ -559,7 +559,7 @@
"first_feature_index = 1\n", "first_feature_index = 1\n",
"second_feature_index = 0\n", "second_feature_index = 0\n",
"\n", "\n",
"colors = ['blue', 'red', 'green']\n", "colors = [\"blue\", \"red\", \"green\"]\n",
"\n", "\n",
"for label, color in zip(range(len(iris.target_names)), colors):\n", "for label, color in zip(range(len(iris.target_names)), colors):\n",
" plt.scatter(\n", " plt.scatter(\n",
@ -571,7 +571,7 @@
"\n", "\n",
"plt.xlabel(iris.feature_names[first_feature_index])\n", "plt.xlabel(iris.feature_names[first_feature_index])\n",
"plt.ylabel(iris.feature_names[second_feature_index])\n", "plt.ylabel(iris.feature_names[second_feature_index])\n",
"plt.legend(loc='upper left')\n", "plt.legend(loc=\"upper left\")\n",
"plt.show()" "plt.show()"
] ]
}, },
@ -772,7 +772,9 @@
} }
], ],
"source": [ "source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.7, test_size=0.3, random_state=42, stratify=y)\n", "X_train, X_test, y_train, y_test = train_test_split(\n",
" X, y, train_size=0.7, test_size=0.3, random_state=42, stratify=y\n",
")\n",
"\n", "\n",
"y_test" "y_test"
] ]
@ -1040,12 +1042,12 @@
" X_test[incorrect_idx, first_feature_index],\n", " X_test[incorrect_idx, first_feature_index],\n",
" X_test[incorrect_idx, second_feature_index],\n", " X_test[incorrect_idx, second_feature_index],\n",
" color=\"darkred\",\n", " color=\"darkred\",\n",
" label='misclassified',\n", " label=\"misclassified\",\n",
")\n", ")\n",
"\n", "\n",
"plt.xlabel('sepal width [cm]')\n", "plt.xlabel(\"sepal width [cm]\")\n",
"plt.ylabel('petal length [cm]')\n", "plt.ylabel(\"petal length [cm]\")\n",
"plt.legend(loc='best')\n", "plt.legend(loc=\"best\")\n",
"plt.title(\"Iris Classification results\")\n", "plt.title(\"Iris Classification results\")\n",
"plt.show()" "plt.show()"
] ]