Last active
February 7, 2019 21:52
-
-
Save pzp1997/3ca05a27a0c10421c906a5af69c46d0a to your computer and use it in GitHub Desktop.
nets213-inclass-analysis.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import csv\n", | |
"\n", | |
"with open('Batch_3517965_batch_results.csv', newline='') as csvfile:\n", | |
" reader = csv.reader(csvfile)\n", | |
" headers = next(reader)\n", | |
"\n", | |
" data = []\n", | |
" for row in reader:\n", | |
" data.append(dict(zip(headers, row)))" | |
], | |
"outputs": [], | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"def count_occurences(column_name):\n", | |
" labels = {}\n", | |
" for entry in data:\n", | |
" entry_label = entry[column_name]\n", | |
" if entry_label in labels:\n", | |
" labels[entry_label] += 1\n", | |
" else:\n", | |
" labels[entry_label] = 1\n", | |
" return labels\n", | |
"\n\n", | |
"def print_counts(counts):\n", | |
" print('\\n'.join(('{}: {}'.format(k, v) for k, v in sorted(counts.items(), key=lambda x: x[1], reverse=True))))" | |
], | |
"outputs": [], | |
"execution_count": 37, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"label_counts = count_occurences('Answer.sentiment.label')\n", | |
"print_counts(label_counts)" | |
], | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Neutral: 393\n", | |
"Negative: 267\n", | |
"Positive: 241\n", | |
"N/A: 106\n", | |
"Extremely Negative: 78\n", | |
"Extremely Positive: 16\n" | |
] | |
} | |
], | |
"execution_count": 38, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"worker_counts = count_occurences('WorkerId')\n", | |
"print_counts(worker_counts)" | |
], | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"A20PV3RB3I0W8S: 207\n", | |
"A2ZBYVQLDUZOV7: 202\n", | |
"A252Z0ZJ7PF59Q: 199\n", | |
"A34M93NJC830DP: 132\n", | |
"A104V8NZIQFN2F: 127\n", | |
"A3O1I9MATO3ZZN: 104\n", | |
"A1DVKS3R9SLQ1H: 68\n", | |
"A35ARURSRU6UAZ: 27\n", | |
"A2HR7ZIX42FEPG: 26\n", | |
"A1APYLD4DUK33J: 3\n", | |
"AKSJ3C5O3V9RB: 2\n", | |
"A3VXSCZ7NP7ZI2: 1\n", | |
"A37WDOIQH6JM6V: 1\n", | |
"A1506T1PAYRT16: 1\n", | |
"A1FVXS8IM5QYO8: 1\n" | |
] | |
} | |
], | |
"execution_count": 39, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [], | |
"outputs": [], | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false, | |
"outputHidden": false, | |
"inputHidden": false | |
} | |
} | |
], | |
"metadata": { | |
"kernel_info": { | |
"name": "python3" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.7.1", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"language": "python", | |
"display_name": "Python 3" | |
}, | |
"nteract": { | |
"version": "0.12.3" | |
}, | |
"gist_id": "3ca05a27a0c10421c906a5af69c46d0a" | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment