Skip to content

Commit 3b3985f

Browse files
Pia SommerauerPia Sommerauer
authored andcommitted
addition to csv reading
1 parent c0099bf commit 3b3985f

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

Chapters/Chapter 16 - Data formats I (CSV and TSV).ipynb

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,39 @@
415415
"cell_type": "markdown",
416416
"metadata": {},
417417
"source": [
418-
"An example of how you can do this is shown below:"
418+
"Can you complete the example below?"
419419
]
420420
},
421421
{
422422
"cell_type": "code",
423-
"execution_count": null,
424-
"metadata": {
425-
"collapsed": true
426-
},
427-
"outputs": [],
423+
"execution_count": 3,
424+
"metadata": {},
425+
"outputs": [
426+
{
427+
"name": "stdout",
428+
"output_type": "stream",
429+
"text": [
430+
"Word roadsweeper\n",
431+
"Bigram 0\n",
432+
"Conc.M 4.85\n",
433+
"Conc.SD 0.37\n",
434+
"Unknown 1\n",
435+
"Total 27\n",
436+
"Percent_known 0.96\n",
437+
"SUBTLEX 0\n",
438+
"Dom_Pos 0\n",
439+
"Word traindriver\n",
440+
"Bigram 0\n",
441+
"Conc.M 4.54\n",
442+
"Conc.SD 0.71\n",
443+
"Unknown 3\n",
444+
"Total 29\n",
445+
"Percent_known 0.90\n",
446+
"SUBTLEX 0\n",
447+
"Dom_Pos 0\n"
448+
]
449+
}
450+
],
428451
"source": [
429452
"data_dict_list = []\n",
430453
"\n",
@@ -435,11 +458,14 @@
435458
"headers = lines[0]\n",
436459
"\n",
437460
"# we consider everythin following the header row as data\n",
438-
"for line in lines[1:]:\n",
461+
"for line in lines[1:3]:\n",
439462
" line_list = line.split('\\t')\n",
440-
" header_list = line.split('\\t')\n",
463+
" header_list = headers.split('\\t')\n",
441464
" row_dict = dict()\n",
465+
" \n",
442466
" # can you think of a way to fill the row dict? \n",
467+
" # hint: check out the zip function\n",
468+
" # zip for iterating over two lists at the same time\n",
443469
" \n",
444470
" ### YOUR CODE ####\n",
445471
" \n",

0 commit comments

Comments
 (0)