{"id":12265,"date":"2020-05-20T17:49:13","date_gmt":"2020-05-21T00:49:13","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12265"},"modified":"2023-12-01T02:47:51","modified_gmt":"2023-12-01T10:47:51","slug":"python-csv-module","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-csv-module\/","title":{"rendered":"The Python CSV Module: Step-By-Step Guide"},"content":{"rendered":"\n<p><em>The Python CSV module is used to handle CSV files. CSV files can hold a lot of information, and the CSV module lets Python read and write to CSV files with the <\/em><code><em>reader()<\/em><\/code><em> and <\/em><code><em>writer()<\/em><\/code><em> functions. <\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Reading, writing, and manipulating data is an essential part of programming. Therefore, it can be useful to know how to handle files in Python, so that you can read and write data from external sources. <\/p>\n\n\n\n<p>For example, let\u2019s say that you are the owner of a local ice cream shop who wants to learn more about customer trends. You could use Python to analyze the data you have gathered on user orders to find out about which flavors of ice cream are popular, how much people spend on those flavors, and more.<\/p>\n\n\n\n<p>This is where the Python CSV module comes in. CSV files are used to store a large amount of data, and the CSV module allows you to parse those files in Python. In this tutorial, we are going to explore how to read and write to CSV files using the CSV Python module.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CSV Refresher<\/h2>\n\n\n\n<p>When you\u2019re working with data, you may have a list of that data separated by commas. For example, you may have a list of ice cream orders whose values are separated with commas. This data structure is referred to as CSV data or Comma-Separated Values.<\/p>\n\n\n\n<p>Traditional text files can be useful for when you need to store data, but they cannot be used to store structured data. CSV files, on the other hand, allow you to store structured data in a table format that you can reference in your code, similar to how spreadsheets and databases allow you to store structured data. For example, you may have a CSV file that stores ice cream flavors or supplier information.<\/p>\n\n\n\n<p>Here\u2019s an example of a CSV file: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>suppliers.csv\nHendersons Creamery, 123 Main Street, Cream\nPeterson Chocolate, 129 Second Street, Chocolate Sprinkles<\/pre><\/div>\n\n\n\n<p>This file stores three items: the name of a supplier, their address, and the product with which they supply our business. Our file also stores two lines of data, one for Hendersons Creamery and the other for Peterson Chocolate.<\/p>\n\n\n\n<p>Because our data is structured in a CSV file, we can parse it through a Python program and get data from individual columns or rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python CSV Module<\/h2>\n\n\n\n<p>The Python CSV module can be used to parse CSV data in Python. So, if you have a CSV file of supplier information, for example, you can use the CSV module to retrieve and work with that data.<\/p>\n\n\n\n<p>CSV is a built-in Python module, but before we start using it, we have to import <code>CSV<\/code> into our program. We can do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Reading CSV Files<\/h3>\n\n\n\n<p>Before you can work with data in a CSV file, you need to read the file. The CSV module comes with a method called <code>reader()<\/code> which can be used to read a CSV file into our program. The reader function takes each line of a specified file and turns it into a list of columns.<\/p>\n\n\n\n<p>Let\u2019s say that we have a list of ice cream suppliers in a file called <code>suppliers.csv<\/code> that we want to read into our program. The contents of the file is as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Hendersons Creamery, 123 Main Street, Cream\nPeterson Chocolate, 129 Second Street, Chocolate Sprinkles\nHW Smith and Co, 17 Boston Avenue, Ice Cream Cones<\/pre><\/div>\n\n\n\n<p>We can retrieve this data using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv\nwith open(\"suppliers.csv\", \"r\") as f:\n\tcontents = csv.reader(f)\n\tfor c in contents:\n\t\tprint(c)<\/pre><\/div>\n\n\n\n<p>There\u2019s a lot going on here, so let\u2019s break it down. On the first line, we import the <code>csv<\/code> module, which allows us to use CSV methods in our code. On the next line, we use a <code>with<\/code> statement to open up our file, and state that our file should be assigned the value <code>f<\/code>. <\/p>\n\n\n\n<p>Next, we use <code>contents = csv.reader(f)<\/code> to read the contents of our file, making use of the <code>csv.reader()<\/code> function. Finally, our program creates a for loop that loops through each line in the CSV file and prints it out to the Python shell.<\/p>\n\n\n\n<p>Our program returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>['Hendersons Creamery', ' 123 Main Street', ' Cream']\n['Peterson Chocolate', ' 129 Second Street', ' Chocolate Sprinkles']\n['HW Smith and Co', ' 17 Boston Avenue', ' Ice Cream Cones']<\/pre><\/div>\n\n\n\n<p>As you can see, our program has read the contents of our file and turned each line into an array. Now that we have this data, we can manipulate it in our program.<\/p>\n\n\n\n<p>Let\u2019s say that we are sending a notice to cancel our orders for next week because the shop will be closed. We could use this code to get the addresses of each supplier so we can send them the notice:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\u2026\n\tfor c in contents:\n\t\tprint(c[1])<\/pre><\/div>\n\n\n\n<p>Our program returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>123 Main Street\n129 Second Street\n17 Boston Avenue<\/pre><\/div>\n\n\n\n<p>In our code, we create a <code>for<\/code> loop that goes through each line in our <code>contents<\/code> variable. Then, we print out the value of each item with the index number <code>1<\/code>, which in this case contains the address of each supplier.<\/p>\n\n\n\n<p>Now, let\u2019s say that we want to read data from our file into an array. This is a common function because it allows us to store our data in another variable for later use. Here\u2019s the code we could use to perform this action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv\nsuppliers = []\nwith open(\"suppliers.csv\", \"r\") as f:\n\tcontents = csv.reader(f)\n\tfor c in contents:\n\t\tsuppliers.append(c)\nprint(suppliers)<\/pre><\/div>\n\n\n\n<p>Our code returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[['Hendersons Creamery', ' 123 Main Street', ' Cream'], ['Peterson Chocolate', ' 129 Second Street', ' Chocolate Sprinkles'], ['HW Smith and Co', ' 17 Boston Avenue', ' Ice Cream Cones']]<\/pre><\/div>\n\n\n\n<p>Let\u2019s explain what is going on in our code. Our program opens the file <code>suppliers.csv<\/code>, reads the file, then appends each record into the array <code>suppliers<\/code> that we declared at the start of our program. Then, our program prints out the variable <code>suppliers<\/code>. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing to CSV Files<\/h3>\n\n\n\n<p>The CSV module contains a method that can be used to write data to a CSV file: <code>writer()<\/code>. The <code>writer()<\/code> function allows us to write data to the file we specify so that we can save our data for later use.<\/p>\n\n\n\n<p>The <code>writer()<\/code> function creates an object that we can use to write to a file. Then, in order to write data to our file, we use the <code>writerow()<\/code> method.<\/p>\n\n\n\n<p>Let\u2019s say that we have written a program that adds a new value to each supplier record. This value holds whether or not the supplier is the primary supplier for a certain product. Here\u2019s the code we could use to write the data we have to a file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv\nsuppliers = []\nwith open(\"suppliers.csv\", \"r\") as f:\n\tcontents = csv.reader(f)\n\tfor c in contents:\n\t\tc.append(\"Yes\")\n\t\tsuppliers.append(c)\nwith open(\"new_suppliers.csv\", \"w\") as f:\nwrite_to_file = csv.writer(f)\nfor s in suppliers:\n\twrite_to_file.writerow(s)<\/pre><\/div>\n\n\n\n<p>The start of our code is very similar to our previous examples; it reads the file <code>suppliers.csv<\/code> and moves its contents to the <code>suppliers<\/code> array. The only difference is that the read function adds a new value called <code>Yes<\/code> to each item in our suppliers array. This value denotes whether or not the supplier is the primary supplier of a certain product.<\/p>\n\n\n\n<p>Next, we open up a new file called <code>new_suppliers.csv<\/code> and write the contents of our <code>suppliers<\/code> to that file. We use the <code>writer()<\/code> function to prepare our file for writing.<\/p>\n\n\n\n<p>Then, we create a <code>for<\/code> loop that goes through our <code>suppliers<\/code> array and uses the <code>writerow()<\/code> method to add each supplier to the <code>new_suppliers.csv<\/code> file.<\/p>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>new_suppliers.csv\nHendersons Creamery, 123 Main Street, Cream,Yes\nPeterson Chocolate, 129 Second Street, Chocolate Sprinkles,Yes\nHW Smith and Co, 17 Boston Avenue, Ice Cream Cones,Yes<\/pre><\/div>\n\n\n\n<p>However, it\u2019s not necessary to loop through each item if we want to write our entire <code>suppliers<\/code> variable to a file. Instead, we can use the <code>writerows()<\/code> method to write every item in the <code>suppliers<\/code> variable to our <code>new_suppliers.csv<\/code> file.<\/p>\n\n\n\n<p>Here\u2019s the code we would use:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\u2026\n\twrite_to_file = csv.writer(f)\n\twrite_to_file.writerows(suppliers)\n\u2026<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>new_suppliers.csv\nHendersons Creamery, 123 Main Street, Cream,Yes\nPeterson Chocolate, 129 Second Street, Chocolate Sprinkles,Yes\nHW Smith and Co, 17 Boston Avenue, Ice Cream Cones,Yes<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CSV File Quoting<\/h3>\n\n\n\n<p>In the above example, our code wrote the <code>suppliers<\/code> array to a new file as it appeared.&nbsp;<\/p>\n\n\n\n<p>However, there may be occasions when you want each value to be written to a file in quotation marks. For example, you may have a list of suppliers where a few supplier names contain commas, which would result in our CSV file becoming malformed.<\/p>\n\n\n\n<p>The CSV module contains four quoting functions that can be used to surround the values to be written to your file in quotation marks so this does not happen. These functions are passed as an argument to the <code>csv.writer()<\/code> method, and are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>csv.QUOTE_ALL<\/code>: Surround every string in quotations<\/li>\n\n\n\n<li><code>csv.QUOTE_NONNUMERIC<\/code>: Quote all string fields<\/li>\n\n\n\n<li><code>csv.QUOTE_MINIMAL<\/code>: Quote fields with special characters<\/li>\n\n\n\n<li><code>csv.QUOTE_NONE<\/code>: Do not quote any values<\/li>\n<\/ul>\n\n\n\n<p>So, let\u2019s say that we want to quote every value in our <code>suppliers<\/code> array when it is written into our file. We could use the following code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\u2026\nwrite_to_file = csv.writer(f, quoting=csv.QUOTE_ALL)\n\u2026<\/pre><\/div>\n\n\n\n<p>Now, when we run our program, our <code>new_suppliers.csv<\/code> file contains the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\"Hendersons Creamery\",\" 123 Main Street\",\" Cream\",\"Yes\"\n\"Peterson Chocolate\",\" 129 Second Street\",\" Chocolate Sprinkles\",\"Yes\"\n\"HW Smith and Co\",\" 17 Boston Avenue\",\" Ice Cream Cones\",\"Yes\"<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Reading data from and writing data to files allows you to retrieve and store data generated from your Python program. For example, if you have a menu of ice cream flavors and prices that you want to work within a Python program, you may want to store the data in a file.<\/p>\n\n\n\n<p>In this tutorial, we explored the basics of the Python CSV module and how it works. We also discussed how to read and write files using the <code>reader()<\/code> and <code>writer()<\/code> objects.<\/p>\n\n\n\n<p>Now you\u2019re ready to read data from and write data to CSV files using Python like a professional!<\/p>\n\n\n\n<p><strong><em>Companies all over the world are hiring people who know how to code in Python. Download the <\/em><\/strong><a href=\"https:\/\/careerkarma.com\/\"><strong><em>free Career Karma app<\/em><\/strong><\/a><strong><em> today to find out more about how learning Python could help you break into a career in tech!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"The Python CSV module is used to handle CSV files. CSV files can hold a lot of information, and the CSV module lets Python read and write to CSV files with the reader() and writer() functions. Reading, writing, and manipulating data is an essential part of programming. Therefore, it can be useful to know how&hellip;","protected":false},"author":240,"featured_media":12266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12265","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>The Python CSV Module: Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-csv-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Python CSV Module: Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-csv-module\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-21T00:49:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:47:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"668\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"The Python CSV Module: Step-By-Step Guide\",\"datePublished\":\"2020-05-21T00:49:13+00:00\",\"dateModified\":\"2023-12-01T10:47:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/\"},\"wordCount\":1432,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/python-csv.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/\",\"name\":\"The Python CSV Module: Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/python-csv.jpg\",\"datePublished\":\"2020-05-21T00:49:13+00:00\",\"dateModified\":\"2023-12-01T10:47:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/python-csv.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/python-csv.jpg\",\"width\":1000,\"height\":668},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-csv-module\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"The Python CSV Module: Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"The Python CSV Module: Step-By-Step Guide | Career Karma","description":"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.","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:\/\/careerkarma.com\/blog\/python-csv-module\/","og_locale":"en_US","og_type":"article","og_title":"The Python CSV Module: Step-By-Step Guide","og_description":"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/python-csv-module\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-05-21T00:49:13+00:00","article_modified_time":"2023-12-01T10:47:51+00:00","og_image":[{"width":1000,"height":668,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"The Python CSV Module: Step-By-Step Guide","datePublished":"2020-05-21T00:49:13+00:00","dateModified":"2023-12-01T10:47:51+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/"},"wordCount":1432,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-csv-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/","url":"https:\/\/careerkarma.com\/blog\/python-csv-module\/","name":"The Python CSV Module: Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg","datePublished":"2020-05-21T00:49:13+00:00","dateModified":"2023-12-01T10:47:51+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The Python CSV module can be used by coders to read from and write to CSV files. Learn about how the CSV module works, and how you can use the CSV reader() and writer() methods on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-csv-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/python-csv.jpg","width":1000,"height":668},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-csv-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"The Python CSV Module: Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12265"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12265\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12266"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}