update lecture material to move to notebook
[harrypotter-wikipedia-cdsw] / harrypotter_minor_edits.ipynb
diff --git a/harrypotter_minor_edits.ipynb b/harrypotter_minor_edits.ipynb
new file mode 100644 (file)
index 0000000..135f4be
--- /dev/null
@@ -0,0 +1,77 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from csv import DictReader"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "input_file = open(\"hp_wiki.tsv\", 'r', encoding='utf-8')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "num_edits = 0\n",
+    "num_anon = 0\n",
+    "for row in DictReader(input_file, delimiter=\"\\t\"):\n",
+    "    num_edits = num_edits + 1\n",
+    "    if row[\"anon\"] == \"True\":\n",
+    "        num_anon = num_anon + 1\n",
+    "\n",
+    "prop_anon = num_anon / num_edits"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "print(f\"total edits: {num_edits}\")\n",
+    "print(f\"anon edits: {num_anon}\")\n",
+    "print(f\"proportion anon: {prop_anon}\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "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.3"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

Benjamin Mako Hill || Want to submit a patch?