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": [
"m1 = np.array([\n",
"m1 = np.array(\n",
" [\n",
" [1, 2, 3, 4, 5],\n",
" [6, 7, 8, 9, 10],\n",
"])\n",
" ]\n",
")\n",
"\n",
"m1"
]

View file

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

View file

@ -56,7 +56,7 @@
" \"orders.csv\",\n",
" index_col=\"order_id\",\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": [
"feature_index = 2\n",
"colors = ['blue', 'red', 'green']\n",
"colors = [\"blue\", \"red\", \"green\"]\n",
"\n",
"for label, color in zip(range(len(iris.target_names)), colors):\n",
" plt.hist(\n",
@ -528,7 +528,7 @@
" )\n",
"\n",
"plt.xlabel(iris.feature_names[feature_index])\n",
"plt.legend(loc='upper right')\n",
"plt.legend(loc=\"upper right\")\n",
"plt.show()"
]
},
@ -559,7 +559,7 @@
"first_feature_index = 1\n",
"second_feature_index = 0\n",
"\n",
"colors = ['blue', 'red', 'green']\n",
"colors = [\"blue\", \"red\", \"green\"]\n",
"\n",
"for label, color in zip(range(len(iris.target_names)), colors):\n",
" plt.scatter(\n",
@ -571,7 +571,7 @@
"\n",
"plt.xlabel(iris.feature_names[first_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()"
]
},
@ -772,7 +772,9 @@
}
],
"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",
"y_test"
]
@ -1040,12 +1042,12 @@
" X_test[incorrect_idx, first_feature_index],\n",
" X_test[incorrect_idx, second_feature_index],\n",
" color=\"darkred\",\n",
" label='misclassified',\n",
" label=\"misclassified\",\n",
")\n",
"\n",
"plt.xlabel('sepal width [cm]')\n",
"plt.ylabel('petal length [cm]')\n",
"plt.legend(loc='best')\n",
"plt.xlabel(\"sepal width [cm]\")\n",
"plt.ylabel(\"petal length [cm]\")\n",
"plt.legend(loc=\"best\")\n",
"plt.title(\"Iris Classification results\")\n",
"plt.show()"
]