X-Git-Url: https://projects.mako.cc/source/harrypotter-wikipedia-cdsw/blobdiff_plain/ce5c13c094d659125fe85d59b9bc0e4c2bf40072..3248892a26a9f80a1a8d6ef5da9ad89a26ca03df:/harrypotter_edit_trend.ipynb diff --git a/harrypotter_edit_trend.ipynb b/harrypotter_edit_trend.ipynb new file mode 100644 index 0000000..13d3d11 --- /dev/null +++ b/harrypotter_edit_trend.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from csv import DictReader" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# read in the input file and count by day\n", + "input_file = open(\"hp_wiki.tsv\", 'r', encoding=\"utf-8\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "edits_by_day = {}\n", + "for row in DictReader(input_file, delimiter=\"\\t\"):\n", + " day_string = row['timestamp'][0:10]\n", + "\n", + " if day_string in edits_by_day:\n", + " edits_by_day[day_string] = edits_by_day[day_string] + 1\n", + " else:\n", + " edits_by_day[day_string] = 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "input_file.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# output the counts by day\n", + "output_file = open(\"hp_edits_by_day.tsv\", \"w\", encoding='utf-8')\n", + "\n", + "# write a header\n", + "print(\"date\\tedits\", file=output_file)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# iterate through every day and print out data into the file\n", + "for day_string in edits_by_day.keys():\n", + " print(\"\\t\".join([day_string, str(edits_by_day[day_string])]), file=output_file)\n", + "\n", + "output_file.close()" + ] + }, + { + "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 +}