{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import csv\n", "\n", "DURATION = 5\n", "FINISHED = 6\n", "PID = 8\n", "\n", "ATTENTION_1 = [40,41]\n", "\n", "SEEN_HOME = 20\n", "SEEN_FRIEND = 21\n", "SEEN_NEIGHBOR = 22\n", "SEEN_RENTAL = 23\n", "SEEN_WORK = 24\n", "\n", "OTHER_SITUATIONS = 25\n", "\n", "DEVICES_OWNED = 26\n", "\n", "HOME_CAMERA_PREF = [27, 31]\n", "HOME_VOICE_PREF = [28, 32]\n", "HOME_LIGHTS_PREF = [29, 33]\n", "HOME_APPS_PREF = [30, 34]\n", "\n", "ACTIONS_HOME = 35\n", "\n", "WILLING_NEIGHBOR = [36, 37]\n", "WILLING_HOUSEMATE = [38, 39]\n", "WILLING_FRIEND = [42, 43]\n", "WILLING_WORK = [44, 45]\n", "\n", "NEIGHBOR_CAMERA_PREF = [46, 50, 54]\n", "NEIGHBOR_VOICE_PREF = [47, 51, 55]\n", "NEIGHBOR_LIGHTS_PREF = [48, 52, 56]\n", "NEIGHBOR_APPS_PREF = [49, 53, 57]\n", "\n", "ACTIONS_NEIGHBOR = 58\n", "\n", "FRIEND_CAMERA_PREF = [59, 63]\n", "FRIEND_VOICE_PREF = [60, 64]\n", "FRIEND_LIGHTS_PREF = [61, 65]\n", "FRIEND_APPS_PREF = [62, 66]\n", "\n", "ACTIONS_FRIEND = 67\n", "\n", "WORK_CAMERA_PREF = [68, 72, 76]\n", "WORK_VOICE_PREF = [69, 73, 77]\n", "WORK_LIGHTS_PREF = [70, 74, 78]\n", "WORK_APPS_PREF = [71, 75, 79]\n", "\n", "ACTIONS_WORK = 80\n", "\n", "\n", "RENTAL_CAMERA_PREF = [81, 85, 89]\n", "RENTAL_VOICE_PREF = [82, 86, 90]\n", "RENTAL_LIGHTS_PREF = [83, 87, 91]\n", "RENTAL_APPS_PREF = [84, 88, 92]\n", "\n", "ACTIONS_RENTAL = 93\n", "\n", "OTHER_SOLNS = 130\n", "\n", "SOLNS_VERY_IMPORTANT = 94\n", "SOLNS_SOMEWHAT_IMPORTANT = 95\n", "SOLNS_NOT_IMPORTANT = 96" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "all_data = []\n", "# Real data starts at row 3 -- previous rows are various types of headers\n", "\n", "with open('feb5_data.csv', 'r') as original:\n", " reader = csv.reader(original)\n", " for row in reader:\n", " all_data.append(row)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "pref_lookup = {\"Strongly appreciate\": 7, \"Appreciate\": 6, \"Somewhat appreciate\": 5, \"Neutral\": 4, \n", " \"Somewhat dislike\": 3, \"Dislike\": 2, \"Strongly dislike\": 1}\n", "\n", "def process_prefs(data_row, which_prefs): \n", " # input: a full row of data, and the variable that indexes some set of prefs (e.g., camera/work)\n", " # output: an int from 1-7 corresponding to what this person's pref was \n", " \n", " for i in which_prefs: \n", " if data_row[i].strip() is not '':\n", " pref = data_row[i].split(' - ')[0]\n", " return(pref_lookup[pref])\n", " \n", "def expand_seen(data_row, which_seen): \n", " # input: a full row of data, and the variable that indexes some set of devices seen/not seen\n", " # output: a list of booleans corresponding to whether each type of device was seen or not, \n", " # and whether (if not, why not) the situation does not apply to the person\n", " # list order is, [bool_camera, bool_voice, bool_lights, bool_apps, string_if_none]\n", " \n", " ret_list = [False, False, False, False, 'n/a']\n", " \n", " seen_str = data_row[which_seen]\n", " \n", " if 'Camera' in seen_str: \n", " ret_list[0] = True\n", " if 'Voice' in seen_str:\n", " ret_list[1] = True\n", " if 'Light' in seen_str: \n", " ret_list[2] = True\n", " if 'Appliances' in seen_str:\n", " ret_list[3] = True\n", " \n", " if ret_list[:4] == [False, False, False, False]: \n", " ret_list[4] = seen_str\n", " \n", " return ret_list\n", "\n", "def process_attention_1(data_row):\n", " if data_row[ATTENTION_1[0]] == \"It depends\": \n", " if data_row[ATTENTION_1[1]].lower() == \"landlord\": \n", " return True\n", " return False" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n", "[False, False, False, False, 'None of these']\n", "True\n" ] } ], "source": [ "# DEMO OF FUNCTIONS\n", "\n", "print(process_prefs(all_data[3], WORK_APPS_PREF))\n", "\n", "print(expand_seen(all_data[10], SEEN_RENTAL))\n", "\n", "print(process_attention_1(all_data[15]))" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "ename": "IndentationError", "evalue": "expected an indented block (, line 2)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m # input: row of data from before\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n" ] } ], "source": [ "def create_output_row(input_row): \n", " # input: row of data from before\n", " # output: row of data in new format (i.e., using functions above to process)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with open('feb5_data_processed.csv', 'w') as output:\n", " # TODO: write header row (can be manual)\n", " for old_row in all_data[4:]: # the 4 here is just because first few rows of original are headers; could remove those eralier\n", " new_row = create_output_row(old_row)\n", " # TODO: write new_row to file" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.16" } }, "nbformat": 4, "nbformat_minor": 2 }