{"id":2823,"date":"2020-05-08T21:17:43","date_gmt":"2020-05-08T21:17:43","guid":{"rendered":"https:\/\/codoid.com\/python-csv-file-read-examples\/"},"modified":"2023-02-28T12:10:22","modified_gmt":"2023-02-28T12:10:22","slug":"python-csv-file-read-examples","status":"publish","type":"post","link":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/","title":{"rendered":"Python CSV File Read Examples"},"content":{"rendered":"<p>CSV stores data in tabular format. Importing CSV files can be achieved at much faster, rate with less memory consumption. In this blog article, we have listed a few Python CSV File Read Examples for your better understanding and reference. We, as a <a href=\"https:\/\/codoid.com\/\">QA company<\/a>, use large CSV files to verify data quality between source and target. In order to automate data quality checks, we use Python libraries to import CSV files programmatically.<\/p>\n<h3>Built-in CSV Library<\/h3>\n<p>Python has built-in CSV library. You can read &#038; write a CSV file. You  needn&#8217;t  install additional packages to use this module.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport csv\r\nwith open('test_data.csv', 'r') as file:\r\n    reader = csv.reader(file)\r\n    for row in reader:\r\n        print(row)\r\n<\/pre>\n<\/div>\n<h3>Read CSV using Pandas<\/h3>\n<p>Pandas is a powerful data analysis Python library. Let\u2019s say for instance if you wish to import large CSV files on one go for Pandas. We, as an <a href=\"https:\/\/codoid.com\/automation-testing-services\/\">automation testing company<\/a> have used Pandas library for our ETL &#038; Data Analytics projects at various occasions and found it noteworthy.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pandas as pd\r\ntest_data = pd.read_csv(&quot;test_data.csv&quot;)\r\n#Reading First Value from name column\r\nprint(test_data[&quot;name&quot;][0])\r\n<\/pre>\n<\/div>\n<h3>Convert XLSX to CSV<\/h3>\n<p>If you want to convert XLSX to CSV in Python programming, you can try out <a href=\"https:\/\/github.com\/dilshod\/xlsx2csv\" target=\"_blank\" rel=\"noopener noreferrer\">xlsx2csv<\/a> library. It  converts large XLSX file to CSV.<\/p>\n<h3>CleverCSV<\/h3>\n<p>CleverCSV detects the dialect of a file automatically , additionally it has command line implementation, if you would like to check the file outside Python environment.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# importing this way makes it easy to port existing code to CleverCSV!\r\nimport clevercsv as csv\r\nwith open(&quot;data.csv&quot;, &quot;r&quot;, newline=&quot;&quot;) as fp:\r\n  # you can use verbose=True to see what CleverCSV does:\r\n  dialect = csv.Sniffer().sniff(fid.read(), verbose=False)\r\n  fp.seek(0)\r\n  reader = csv.reader(fp, dialect)\r\n  rows = list(reader)\r\n<\/pre>\n<\/div>\n<h3>In Conclusion<\/h3>\n<p>When you use Python libraries, you can craft your test automation scripts quickly and concisely instead of writing lengthy snippets. The above listed libraries will be helpful when you handle CSV files. We, as a <a href=\"https:\/\/codoid.com\/software-testing-company\/\">software testing company<\/a>, use various Python packages for <b>ETL<\/b> &#038; <b>Data Analytics<\/b> testing projects. There are several other Python CSV File Read packages available in the market, However, they are not active in development. We hope you enjoyed this blog article and found it worthwhile.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSV stores data in tabular format. Importing CSV files can be achieved at much faster, rate with less memory consumption. In this blog article, we have listed a few Python CSV File Read Examples for your better understanding and reference. We, as a QA company, use large CSV files to verify data quality between source [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5059,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[181,179,20],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v20.3) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python CSV File Read Examples - Codoid<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python CSV File Read Examples\" \/>\n<meta property=\"og:description\" content=\"CSV stores data in tabular format. Importing CSV files can be achieved at much faster, rate with less memory consumption. In this blog article, we have listed a few Python CSV File Read Examples for your better understanding and reference. We, as a QA company, use large CSV files to verify data quality between source [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Codoid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codoid.softwaretestingcompany\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-08T21:17:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-28T12:10:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2020\/05\/python_csv.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codoid\" \/>\n<meta name=\"twitter:site\" content=\"@codoid\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python CSV File Read Examples - Codoid","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Python CSV File Read Examples","og_description":"CSV stores data in tabular format. Importing CSV files can be achieved at much faster, rate with less memory consumption. In this blog article, we have listed a few Python CSV File Read Examples for your better understanding and reference. We, as a QA company, use large CSV files to verify data quality between source [&hellip;]","og_url":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2020-05-08T21:17:43+00:00","article_modified_time":"2023-02-28T12:10:22+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/05\/python_csv.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/software-testing\/python-csv-file-read-examples\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Python CSV File Read Examples","datePublished":"2020-05-08T21:17:43+00:00","dateModified":"2023-02-28T12:10:22+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/software-testing\/python-csv-file-read-examples\/"},"wordCount":417,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Software Testing","Fixed","Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/software-testing\/python-csv-file-read-examples\/","url":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/","name":"Python CSV File Read Examples - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2020-05-08T21:17:43+00:00","dateModified":"2023-02-28T12:10:22+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/software-testing\/python-csv-file-read-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Python CSV File Read Examples"}]},{"@type":"WebSite","@id":"https:\/\/codoid.com\/#website","url":"https:\/\/codoid.com\/","name":"Codoid","description":"","publisher":{"@id":"https:\/\/codoid.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codoid.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codoid.com\/#organization","name":"Codoid - Software Testing Company","url":"https:\/\/codoid.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/","url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","contentUrl":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","width":500,"height":500,"caption":"Codoid - Software Testing Company"},"image":{"@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codoid.softwaretestingcompany","https:\/\/twitter.com\/codoid","https:\/\/www.instagram.com\/codoid.softwaretestingcompany\/","https:\/\/www.linkedin.com\/company\/codoid-qacompany","https:\/\/www.pinterest.com\/codoid9282\/codoid-software-testing-company\/","https:\/\/www.youtube.com\/channel\/UCCmOTDQgcf4W8oo22mBMUYA"]},{"@type":"Person","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codoid.com"]}]}},"_links":{"self":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2823"}],"collection":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/comments?post=2823"}],"version-history":[{"count":4,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2823\/revisions"}],"predecessor-version":[{"id":11499,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2823\/revisions\/11499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/5059"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=2823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=2823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=2823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}