{"id":13857,"date":"2021-06-22T12:05:32","date_gmt":"2021-06-22T06:35:32","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=13857"},"modified":"2021-06-22T12:06:52","modified_gmt":"2021-06-22T06:36:52","slug":"read-tsv-file-python","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/","title":{"rendered":"Simple Ways to Read TSV Files in Python"},"content":{"rendered":"\n<p>Files are used for storing information with the ability to read and write on them. The operations which can be performed on files in python are \u2013 read, write, open, close, rename and delete. There are two main types of files in python \u2013 binary file and text file. Binary files can be of various types such as image files like .png, .gif, .jpg or documents like <a href=\"http:\/\/www.pythonpool.com\/python-pdf-parser\/\" target=\"_blank\" rel=\"noopener\">.pdf<\/a>, .xls, .doc, etc. The <a href=\"http:\/\/www.pythonpool.com\/python-text-to-pdf\/\" target=\"_blank\" rel=\"noreferrer noopener\">text file<\/a> can be source code, web standards, tabular data, etc. In this article, we shall be looking into one such tabular data from the text file \u2013<em> .tsv<\/em> file. We shall be seeing into how to<strong> read tsv file in python<\/strong>.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#What_is_a_TSV_file\" >What is a TSV file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Reading_TSV_file_in_Python_Using_open_Function\" >Reading TSV file in Python Using open Function<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#The_Entire_Code_is\" >The Entire Code is:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Reading_TSV_file_in_Python_Using_Pandas\" >Reading TSV file in Python Using Pandas<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#The_Entire_Code_is-2\" >The Entire Code is:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Writing_Over_a_TSV_File_with_Pandas\" >Writing Over a TSV File with Pandas<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Writing_TSV_Without_Pandas\" >Writing TSV Without Pandas<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Reading_TSV_into_dictionary_with_open\" >Reading TSV into dictionary with open()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#Must_Read\" >Must, Read<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-tsv-file\"><span class=\"ez-toc-section\" id=\"What_is_a_TSV_file\"><\/span>What is a TSV file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>The<em> TSV<\/em> file stands for tab-separated values file. It is a text file that stores data in a tabular form. The <em>TSV<\/em> file format is widely used for exchanging data between <a href=\"http:\/\/www.pythonpool.com\/python-code-to-convert-a-table-to-first-normal-form\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"text-decoration: underline;\">databases in the form of a database table<\/span> <\/a>or spreadsheet data. Here, each record is separated from the other by a tab character <em>( \\t )<\/em>. It acts as an alternate format to the <em>.csv <\/em>format. The difference between<em> .tsv<\/em> and<em> .csv <\/em>format is that the <em>.csv <\/em>format uses commas to separate columns in data whereas<em> .tsv<\/em> format uses tabs to separate columns.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-reading-tsv-file-in-python-using-open-function\"><span class=\"ez-toc-section\" id=\"Reading_TSV_file_in_Python_Using_open_Function\"><\/span>Reading TSV file in Python Using open Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can read the <em>tsv<\/em> file in python using <em><strong>the <\/strong><\/em><strong><em>open()<\/em> function<\/strong>. We can read a given file with the help of the<em> open() <\/em>function. After reading, it returns a file object for the same. With <strong><em>open()<\/em>, we can perform several file handling operations<\/strong> on the file such as reading, writing, appending, and creating files. <\/p>\n\n\n\n<p>After opening the file, we shall make use of the <em><strong>reader() present in CSV to convert the file object into CSV.reader object. For using the reader, we shall be first importing CSV<\/strong><\/em>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport csv\n<\/pre><\/div>\n\n\n<p>Then, we shall write the <em>open() <\/em>function. We shall be using a <em>tsv<\/em> file named <em>&#8216;product.tsv&#8217;<\/em> , which consists of the sales count for three products over a span of 12 months. We will pass the <em>tsv<\/em> file as an argument to the <em>open() <\/em>function, and &#8216;file&#8217; will be the file&#8217;s object. <\/p>\n\n\n\n<p>Then we use<em> csv.reader <\/em>to convert the file object to<em><strong> csv.reader<\/strong> <\/em>object. We pass the delimiter as<strong><em> &#8216;\\t&#8217;<\/em> <\/strong>to the <em><strong>csv.reader<\/strong><\/em>. The delimiter is used to indicate the character which will be separating each field. <\/p>\n\n\n\n<p>Since this is a <em>tsv <\/em>file, we shall be passing the tab character as the delimiter. The variable <em>&#8216;tsv_file&#8217; <\/em>will be the object for the<em> tsv<\/em> file. Then, we shall iterate the entire file and print each statement line by line. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwith open(&quot;product.tsv&quot;) as file:\n    tsv_file = csv.reader(file, delimiter=&quot;\\t&quot;)\n    for line in tsv_file:\n        print(line)\n<\/pre><\/div>\n\n\n<p><strong>The tsv file is printed line by line as the output<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['Month', 'Product A Sales', 'Product B Sales', 'Product C Sales']\n['January', '297', '119', '289']\n['February', '305', '437', '362']\n['March', '234', '247', '177']\n['April', '184', '193', '219']\n['May', '373', '316', '177']\n['June', '433', '169', '370']\n['July', '294', '403', '429']\n['August', '156', '445', '216']\n['September', '441', '252', '498']\n['October', '328', '472', '491']\n['November', '270', '251', '372']\n['December', '146', '159', '156']<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-entire-code-is\"><span class=\"ez-toc-section\" id=\"The_Entire_Code_is\"><\/span>The Entire Code is:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport csv\nwith open(&quot;product.tsv&quot;) as file:\n    tsv_file = csv.reader(file, delimiter=&quot;\\t&quot;)\n    for line in tsv_file:\n        print(line)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-reading-tsv-file-in-python-using-pandas\"><span class=\"ez-toc-section\" id=\"Reading_TSV_file_in_Python_Using_Pandas\"><\/span>Reading TSV file in Python Using Pandas<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There is another way to read the tsv file which is using the pandas library.  Pandas library in python is used for performing data analysis and data manipulation. It is a powerful library for manipulating numerical tables.<\/p>\n\n\n\n<p><strong>First, we shall be importing the pandas library. <\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pandas as pd\n<\/pre><\/div>\n\n\n<p>Now, we shall be making use of the <strong><em>read_csv()<\/em> <\/strong>function from the pandas library. We shall be passing the<em> tsv <\/em>file to the <em><strong>read_csv()<\/strong>.<\/em> Along with the file, we shall be passing separator as<em> &#8216;\\t&#8217; <\/em>for the tab character because, for<em> tsv<\/em> files, the tab character will separate each field. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntsv_data = pd.read_csv('product.tsv', sep='\\t')\ntsv_data\n<\/pre><\/div>\n\n\n<p><strong>The output will be the <em>tsv<\/em> file:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"830\" height=\"624\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/image-38.png\" alt=\"read tsv file python\" class=\"wp-image-13862\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/image-38.png 830w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/image-38-300x226.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/image-38-768x577.png 768w\" sizes=\"(max-width: 830px) 100vw, 830px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-entire-code-is-1\"><span class=\"ez-toc-section\" id=\"The_Entire_Code_is-2\"><\/span>The Entire Code is:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pandas as pd\ntsv_data = pd.read_csv('product.tsv', sep='\\t')\ntsv_data\n<\/pre><\/div>\n\n\n<p>Now, to read the first five rows from the <em>product.tsv<\/em>, we shall make use of<em> head() <\/em>function. This will get the first n rows from the <em>tsv <\/em>file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nprint(tsv_data.head())\n<\/pre><\/div>\n\n\n<p><strong> By default, if you don&#8217;t specify the number of rows, <em>head()<\/em> will print 5 rows.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n      Month  Product A Sales  Product B Sales  Product C Sales\n0   January              297              119              289\n1  February              305              437              362\n2     March              234              247              177\n3     April              184              193              219\n4       May              373              316              177\n<\/pre><\/div>\n\n\n<p>To print all the entries of a particular <a href=\"https:\/\/en.wikipedia.org\/wiki\/Column\" target=\"_blank\" rel=\"noreferrer noopener\">column<\/a>, we shall be using the following code. We will print the entire <em>&#8216;Product A Sales&#8217; <\/em>column.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nprint(tsv_data&#x5B;'Product A Sales'])\n<\/pre><\/div>\n\n\n<p><strong>The output will be:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0     297\n1     305\n2     234\n3     184\n4     373\n5     433\n6     294\n7     156\n8     441\n9     328\n10    270\n11    146\nName: Product A Sales, dtype: int64<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-over-a-tsv-file-with-pandas\"><span class=\"ez-toc-section\" id=\"Writing_Over_a_TSV_File_with_Pandas\"><\/span>Writing Over a TSV File with Pandas<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now, we shall see how to write over an already existing<em> tsv<\/em> file. We shall make use of the <em>open()<\/em> function but this time we shall open the file in<em> <\/em><strong><em>&#8216;wt&#8217; <\/em>mode<\/strong>. Using<em> &#8216;<strong>wt&#8217; <\/strong><\/em>mode, we can write the file as text. Instead of the<em> <strong>csv.reader()<\/strong><\/em>, here we shall be using<em> <strong>csv.writer()<\/strong><\/em>. We shall pass the<em> tsv<\/em> file and the delimiter as <em>&#8216;\\t&#8217; <\/em>to the <em>writer() <\/em>function. <\/p>\n\n\n\n<p><strong>After that, we shall use <em>writerow() <\/em>to write individual rows to the file. Finally, we shall insert two rows using the same function.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport csv\n\nwith open('product.tsv', 'wt') as file:\n    tsv_writer = csv.writer(file, delimiter='\\t')\n    tsv_writer.writerow(&#x5B;'January', 324, 122, 191])\n    tsv_writer.writerow(&#x5B;'February', 291, 322, 291])\n<\/pre><\/div>\n\n\n<p> Now, let us try to again read the<em> <\/em><strong><em>&#8216;product.tsv&#8217; <\/em>file. Again, we<\/strong> shall use the same piece of code as used before for reading.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwith open(&quot;product.tsv&quot;) as file:\n    tsv_file = csv.reader(file, delimiter=&quot;\\t&quot;)\n    for line in tsv_file:\n        print(line)\n<\/pre><\/div>\n\n\n<p>For the output, we can see that the file has been overwritten and it only contains two rows instead of the twelve rows which were present before. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['January', '324', '122', '191']\n['February', '291', '322', '291']<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-tsv-without-pandas\"><span class=\"ez-toc-section\" id=\"Writing_TSV_Without_Pandas\"><\/span>Writing TSV Without Pandas<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"h-\">To write over tsv files without using the pandas library, we shall use the following code. Here, we will append the contents of a file named &#8216;total_sales&#8217; into another tsv file named &#8216;product&#8217;. The &#8216;total_sales&#8217; consists of sales for all the products for a year, whereas the &#8216;product&#8217; consists of sales for all in products individually.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwith open(&quot;total_sales.tsv&quot;) as file:\n  for line in file:\n    with open('product.tsv', &quot;a&quot;) as f:\n      f.write(line)\n<\/pre><\/div>\n\n\n<p id=\"h-\"><strong> Now, to read the file:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport csv\nwith open(&quot;product.tsv&quot;) as file:\n    tsv_file = csv.reader(file, delimiter=&quot;\\t&quot;)\n    for line in tsv_file:\n        print(line)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['Month', 'Product A Sales', 'Product B Sales', 'Product C Sales']\n['January', '297', '119', '289']\n['February', '305', '437', '362']\n['March', '234', '247', '177']\n['April', '184', '193', '219']\n['May', '373', '316', '177']\n['June', '433', '169', '370']\n['July', '294', '403', '429']\n['August', '156', '445', '216']\n['September', '441', '252', '498']\n['October', '328', '472', '491']\n['November', '270', '251', '372']\n['December', '146', '159', '156Month', 'Total Sales']\n['January', '558']\n['February', '871']\n['March', '756']\n['April', '509']\n['May', '987']\n['June', '625']\n['July', '862']\n['August', '548']\n['September', '669']\n['October', '827']\n['November', '776']\n['December', '955']<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>As seen above, the &#8216;product&#8217; file has been appended with the contents of the &#8216;total_sales&#8217; file.<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-reading-tsv-into-dictionary-with-open\"><span class=\"ez-toc-section\" id=\"Reading_TSV_into_dictionary_with_open\"><\/span>Reading TSV into dictionary with open()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can read a given tsv file and store its contents into a dictionary. To achieve that, we shall be taking a tsv file containing two columns &#8211; month and total sales. Then, with the help of the open() function, we shall store each month as the dictionary&#8217;s key and the total sales amount for the month as the values. <\/p>\n\n\n\n<p><strong>We shall split the month and sales using the tab character. Then, we shall enumerate over the dictionary and print its values.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsales_dictionary = {}\nwith open(&quot;total_sales.tsv&quot;) as f:\n  for line in f:\n    (month, sales)=line.split('\\t')\n    sales_dictionary&#x5B;month]=sales\n\nfor i,month in enumerate(sales_dictionary):\n  print(f'{month} : {sales_dictionary&#x5B;month]}')\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Month : Total Sales\n\nJanuary : 558\n\nFebruary : 871\n\nMarch : 756\n\nApril : 509\n\nMay : 987\n\nJune : 625\n\nJuly : 862\n\nAugust : 548\n\nSeptember : 669\n\nOctober : 827\n\nNovember : 776\n\nDecember : 955<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must, Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links\"><li><a href=\"http:\/\/www.pythonpool.com\/numpy-axis\/\">Numpy Axis in Python With Detailed Examples<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/numpy-array-to-pandas-dataframe\/\">How to Convert Numpy Array to Pandas Dataframe<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-save-variable-to-file\/\">How to Save a Variable in a File in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/numpy-read-csv\/\">6 Ways to Read a CSV file with Numpy in Python<\/a><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p>That sums up everything about the <em>tsv<\/em> file. If you have any questions, let us know in the comments below.<\/p>\n\n\n\n<p><em>Until next time, Keep Learning!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Files are used for storing information with the ability to read and write on them. The operations which can be performed on files in python &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Simple Ways to Read TSV Files in Python\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#more-13857\" aria-label=\"More on Simple Ways to Read TSV Files in Python\">Read more<\/a><\/p>\n","protected":false},"author":20,"featured_media":13884,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[4258,4257,4259,4255,4256,4254],"class_list":["post-13857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-how-to-read-tsv-file-in-python","tag-how-to-read-a-tsv-file-in-python","tag-python-read-tsv-file","tag-read-a-tsv-file-in-python-returns-a-null","tag-read-tsv-file-in-python","tag-read-tsv-file-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Simple Ways to Read TSV Files in Python - Python Pool<\/title>\n<meta name=\"description\" content=\"The TSV file stands for tab separated values file. To read a tsv file in python, we can use either the open function or the pandas library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple Ways to Read TSV Files in Python\" \/>\n<meta property=\"og:description\" content=\"Files are used for storing information with the ability to read and write on them. The operations which can be performed on files in python are \u2013 read,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-22T06:35:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-22T06:36:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dhruvi Vikma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dhruvi Vikma\" \/>\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:\/\/www.pythonpool.com\/read-tsv-file-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\"},\"author\":{\"name\":\"Dhruvi Vikma\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\"},\"headline\":\"Simple Ways to Read TSV Files in Python\",\"datePublished\":\"2021-06-22T06:35:32+00:00\",\"dateModified\":\"2021-06-22T06:36:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\"},\"wordCount\":1039,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg\",\"keywords\":[\"how to read .tsv file in python\",\"how to read a tsv file in python\",\"python read tsv file\",\"read a tsv file in python returns a null\",\"read tsv file in python\",\"read tsv file python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\",\"url\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\",\"name\":\"Simple Ways to Read TSV Files in Python - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg\",\"datePublished\":\"2021-06-22T06:35:32+00:00\",\"dateModified\":\"2021-06-22T06:36:52+00:00\",\"description\":\"The TSV file stands for tab separated values file. To read a tsv file in python, we can use either the open function or the pandas library.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg\",\"width\":1350,\"height\":650,\"caption\":\"read tsv file python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simple Ways to Read TSV Files in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\",\"name\":\"Dhruvi Vikma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"caption\":\"Dhruvi Vikma\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Simple Ways to Read TSV Files in Python - Python Pool","description":"The TSV file stands for tab separated values file. To read a tsv file in python, we can use either the open function or the pandas library.","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:\/\/www.pythonpool.com\/read-tsv-file-python\/","og_locale":"en_US","og_type":"article","og_title":"Simple Ways to Read TSV Files in Python","og_description":"Files are used for storing information with the ability to read and write on them. The operations which can be performed on files in python are \u2013 read,","og_url":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/","og_site_name":"Python Pool","article_published_time":"2021-06-22T06:35:32+00:00","article_modified_time":"2021-06-22T06:36:52+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg","type":"image\/jpeg"}],"author":"Dhruvi Vikma","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Dhruvi Vikma","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/"},"author":{"name":"Dhruvi Vikma","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23"},"headline":"Simple Ways to Read TSV Files in Python","datePublished":"2021-06-22T06:35:32+00:00","dateModified":"2021-06-22T06:36:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/"},"wordCount":1039,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg","keywords":["how to read .tsv file in python","how to read a tsv file in python","python read tsv file","read a tsv file in python returns a null","read tsv file in python","read tsv file python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/read-tsv-file-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/","url":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/","name":"Simple Ways to Read TSV Files in Python - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg","datePublished":"2021-06-22T06:35:32+00:00","dateModified":"2021-06-22T06:36:52+00:00","description":"The TSV file stands for tab separated values file. To read a tsv file in python, we can use either the open function or the pandas library.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/read-tsv-file-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Simple-Ways-to-Read-TSV-Files-in-Python.jpg","width":1350,"height":650,"caption":"read tsv file python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/read-tsv-file-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Simple Ways to Read TSV Files in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23","name":"Dhruvi Vikma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","caption":"Dhruvi Vikma"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=13857"}],"version-history":[{"count":24,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13857\/revisions"}],"predecessor-version":[{"id":24395,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13857\/revisions\/24395"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/13884"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=13857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=13857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=13857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}