{"id":1202,"date":"2020-11-13T01:33:38","date_gmt":"2020-11-13T01:33:38","guid":{"rendered":"http:\/\/learnlearn.uk\/alevelcs\/?page_id=1202"},"modified":"2021-03-26T06:51:48","modified_gmt":"2021-03-26T06:51:48","slug":"reading-writing-csv-files","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/","title":{"rendered":"Reading and Writing CSV Files"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Reading CSV Files to lists<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Reading CSV Files into Python lists<\/h3>\n<p>Good for:<\/p>\n<ul>\n<li>Looping through the entire list of rows in the file and doing something for each row.<\/li>\n<li>Finding the highest, lowest and average for items in CSV rows.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1-3aBKPaxiZzuQ8PCyuIvNFvs-amQvRKE\/view?usp=sharing\">YouTube Blocked? Try the Google Drive Version<\/a><\/p>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEw\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Reading a CSV file into a Python List\" title=\"Play video &quot;Reading a CSV file into a Python List&quot;\">https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEw<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEw\" title=\"Reading a CSV file into a Python List\">Reading a CSV file into a Python List (https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEw)<\/a><\/noscript><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Reading CSV files to Dictionaries<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Reading CSV Files into Python Dictionaries<\/h3>\n<p>Good for:<\/p>\n<ul>\n<li>Where you just want find information about a specific item in a CSV file.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1W0ALqBJoD-tQF3Sdkhymy_ofjJrPtwDf\/view?usp=sharing\">Can&#8217;t access YouTube? Try the Google Drive Version.<\/a><\/p>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=zvrRI0r6f2Q\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Reading a CSV file into a Python Dictionary\" title=\"Play video &quot;Reading a CSV file into a Python Dictionary&quot;\">https:\/\/www.youtube.com\/watch?v=zvrRI0r6f2Q<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=zvrRI0r6f2Q\" title=\"Reading a CSV file into a Python Dictionary\">Reading a CSV file into a Python Dictionary (https:\/\/www.youtube.com\/watch?v=zvrRI0r6f2Q)<\/a><\/noscript><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Writing to CSV Files<\/h2>\n<div class=\"tabcontent\">\n\n<p><strong>Tutorial Video<\/strong><\/p>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1hqp3KGwyMVsasWBi0-OOevdWf3BVGfA5\/view?usp=sharing\">YouTube Blocked? Use the Google Drive version instead<\/a><\/p>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=DXzEijPCRc8\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Python - How to write to a CSV file\" title=\"Play video &quot;Python - How to write to a CSV file&quot;\">https:\/\/www.youtube.com\/watch?v=DXzEijPCRc8<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=DXzEijPCRc8\" title=\"Python - How to write to a CSV file\">Python &#8211; How to write to a CSV file (https:\/\/www.youtube.com\/watch?v=DXzEijPCRc8)<\/a><\/noscript><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre>import csv\r\nf = open('namesages.csv','a',newline = '')\r\n\r\nname = input(\"What is your name?\")\r\nage = input(\"What is your age?\")\r\n\r\nrow = (name,age)\r\n\r\nwriter = csv.writer(f)\r\nwriter.writerow(row)\r\n\r\nf.close() #really important!!!<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Reading CSV Files into Python lists Good for: Looping through the entire list of rows in the file and doing something for each row. Finding the highest, lowest and average for items in CSV rows. YouTube Blocked? Try the Google Drive Version https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEwVideo can&#8217;t be loaded because JavaScript is disabled: Reading a CSV file into&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Reading and Writing CSV Files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reading and Writing CSV Files - A Level Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reading and Writing CSV Files - A Level Computer Science\" \/>\n<meta property=\"og:description\" content=\"Reading CSV Files into Python lists Good for: Looping through the entire list of rows in the file and doing something for each row. Finding the highest, lowest and average for items in CSV rows. YouTube Blocked? Try the Google Drive Version https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEwVideo can&#8217;t be loaded because JavaScript is disabled: Reading a CSV file into&hellip;&nbsp;Read More &raquo;Reading and Writing CSV Files\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\" \/>\n<meta property=\"og:site_name\" content=\"A Level Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-26T06:51:48+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\",\"name\":\"Reading and Writing CSV Files - A Level Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\"},\"datePublished\":\"2020-11-13T01:33:38+00:00\",\"dateModified\":\"2021-03-26T06:51:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"A Level Computer Science Home\",\"item\":\"https:\/\/learnlearn.uk\/alevelcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reading and Writing CSV Files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"name\":\"A Level Computer Science\",\"description\":\"CIE Specification\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\",\"name\":\"A Level Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"A Level Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reading and Writing CSV Files - A Level Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/","og_locale":"en_GB","og_type":"article","og_title":"Reading and Writing CSV Files - A Level Computer Science","og_description":"Reading CSV Files into Python lists Good for: Looping through the entire list of rows in the file and doing something for each row. Finding the highest, lowest and average for items in CSV rows. YouTube Blocked? Try the Google Drive Version https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEwVideo can&#8217;t be loaded because JavaScript is disabled: Reading a CSV file into&hellip;&nbsp;Read More &raquo;Reading and Writing CSV Files","og_url":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/","og_site_name":"A Level Computer Science","article_modified_time":"2021-03-26T06:51:48+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/","url":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/","name":"Reading and Writing CSV Files - A Level Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#website"},"datePublished":"2020-11-13T01:33:38+00:00","dateModified":"2021-03-26T06:51:48+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/alevelcs\/reading-writing-csv-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"A Level Computer Science Home","item":"https:\/\/learnlearn.uk\/alevelcs\/"},{"@type":"ListItem","position":2,"name":"Reading and Writing CSV Files"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/alevelcs\/#website","url":"https:\/\/learnlearn.uk\/alevelcs\/","name":"A Level Computer Science","description":"CIE Specification","publisher":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization","name":"A Level Computer Science","url":"https:\/\/learnlearn.uk\/alevelcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"A Level Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/alevelcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Reading CSV Files into Python lists Good for: Looping through the entire list of rows in the file and doing something for each row. Finding the highest, lowest and average for items in CSV rows. YouTube Blocked? Try the Google Drive Version https:\/\/www.youtube.com\/watch?v=bJDZ1wNKGEwVideo can&#8217;t be loaded because JavaScript is disabled: Reading a CSV file into&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1202"}],"collection":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/comments?post=1202"}],"version-history":[{"count":3,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1202\/revisions"}],"predecessor-version":[{"id":1867,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1202\/revisions\/1867"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/media?parent=1202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}