

{"id":20709,"date":"2018-07-11T04:10:22","date_gmt":"2018-07-11T04:10:22","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=20709"},"modified":"2026-04-20T16:19:01","modified_gmt":"2026-04-20T10:49:01","slug":"python-data-file-formats","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/","title":{"rendered":"Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1891,&quot;href&quot;:&quot;https:\\\/\\\/docs.python.org\\\/2\\\/library\\\/fileformats.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250305190701\\\/https:\\\/\\\/docs.python.org\\\/2\\\/library\\\/fileformats.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 06:58:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-19 03:23:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-22 22:36:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-29 11:35:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-22 18:14:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-29 19:39:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-04 21:18:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 18:00:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 11:25:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-01 18:02:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 09:12:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 07:14:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-24 06:49:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-01 12:18:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-06 18:08:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 11:48:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-28 13:52:50&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-28 13:52:50&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In our last python tutorial, we studied\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/relational-database-with-python\/\"><strong>How to Work with Relational Database with Python<\/strong><\/a>. In this tutorial, we will discuss different types of Python Data File Formats: Python\u00a0CSV, JSON, and\u00a0XLS. Moreover, we will discuss how to read CSV, JSON, XLS<a href=\"https:\/\/data-flair.training\/blogs\/python-file\/\"><strong> files in Python Programming Language<\/strong><\/a>.<\/p>\n<p>Learning these data formats will help you handle data more easily, especially in areas like data analysis, machine learning, and automation.<\/p>\n<p>We will also look into the simple examples to understand how Python works with these file formats.<\/p>\n<p>So, let&#8217;s see Data File Formats in Python.<\/p>\n<h3>Python Data File Formats<\/h3>\n<p>Let\u2019s first learn a little about the Python Data File formats we will be processing.<\/p>\n<h4>a.\u00a0Python Data File Formats &#8211;\u00a0Python CSV<\/h4>\n<p>Python CSV data is a basic with data science. A Comma-Separated-Value file uses commas to separate values. You can look at it as a delimited text file that holds tabular data as plain text. One problem with this may arise when the data it holds contains a comma or a line break- we can use other delimiters like a tab stop. This Python data file format proves useful in exchanging data and in moving tabular data between programs. The extension for a CSV file is .csv.<\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-read-and-write-file\/\">Follow this link to know about File Handling In Python<\/a><\/strong><\/p>\n<p>Here\u2019s a Python CSV file we will use for our demo-<br \/>\nid,title,timing,genre,rating<br \/>\n1,Dog with a Blog,17:30-18:00,Comedy,4.7<br \/>\n2,Liv and Maddie,18:00-18:30,Comedy,6.3<br \/>\n3,Girl Meets World,18:30-19:00,Comedy,7.2<br \/>\n4,KC Undercover,19:00-19:30,Comedy,6.1<br \/>\n5,Austin and Ally,19:30-20:00,Comedy,6<\/p>\n<p>We saved this as <em>schedule.csv<\/em> on our Desktop. Remember to save as <em>All files (*.*)<\/em>. When we open this file, it opens in Microsoft Excel by default on Windows-<\/p>\n<div id=\"attachment_20723\" style=\"width: 539px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/csv-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20723\" class=\"wp-image-20723 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/csv-1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"529\" height=\"237\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/csv-1.png 529w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/csv-1-150x67.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/csv-1-300x134.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/a><p id=\"caption-attachment-20723\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<h4>b.\u00a0Python Data File Formats &#8211;\u00a0Python JSON<\/h4>\n<p>JSON stands for JavaScript Object Notation and is an open standard file format. While it holds attribute-value pairs and array data types, it uses human-readable text for this. This Python data file format is language-independent, and we can use it in asynchronous browser-server communication. The extension for a Python JSON file is .json.<\/p>\n<p>Load a JSON file with three words: data = json.load(open(&#8220;profile.json&#8221;)). The json module turns nested braces into native dicts and lists, so you can grab fields like data[&#8220;email&#8221;] instantly.<\/p>\n<div id=\"attachment_20724\" style=\"width: 250px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/json.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20724\" class=\"wp-image-20724 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/json.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"240\" height=\"240\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/json.png 240w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/json-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/json-100x100.png 100w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><p id=\"caption-attachment-20724\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-zipfile\/\">Let&#8217;s Explore Python Zipfile \u2013 Benefits, Modules, Objects<\/a><\/strong><br \/>\nHere\u2019s the JSON file in Python we will use for the demo-<\/p>\n<pre class=\"EnlighterJSRAW\">{\r\n\"ID\":[\"1\",\"2\",\"3\",\"4\",\"5\"],\r\n\"Title\":[\"Dog with a Blog\",\"Liv and Maddie\",\"Girl Meets World\",\"KC Undercover\",\"Austin and Ally\"],\r\n\"Timing\":[\"17:30-18:00\",\"18:00-18:30\",\"18:30-19:00\",\"19:00-19:30\",\"19:30-20:00\"],\r\n\"Genre\":[\"Comedy\",\"Comedy\",\"Comedy\",\"Comedy\",\"Comedy\"],\r\n\"Rating\":[\"4.7\",\"6.3\",\"7.2\",\"6.1\",\"6\"]\r\n}<\/pre>\n<p>We save this as <em>schedule.json<\/em> on the Desktop.<\/p>\n<h4>c. Python Data File Formats &#8211;\u00a0Python XLS<\/h4>\n<p>The extension for an Excel spreadsheet is .xlsx. This proves useful for data science; we create a workbook with two sheets in Microsoft Excel.<br \/>\nSheet 1-<\/p>\n<div id=\"attachment_20725\" style=\"width: 535px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20725\" class=\"wp-image-20725 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"525\" height=\"212\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls1.png 525w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls1-150x61.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls1-300x121.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><p id=\"caption-attachment-20725\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p>Sheet 2-<\/p>\n<div id=\"attachment_20726\" style=\"width: 351px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20726\" class=\"wp-image-20726 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls2.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"341\" height=\"217\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls2.png 341w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls2-150x95.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xls2-300x191.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/a><p id=\"caption-attachment-20726\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p>We save this workbook as <em>schedule.xlsx<\/em> on our Desktop.<br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/xml-processing-python-3\/\">Do you Know the XML Processing in Python 3\u00a0<\/a><\/strong><\/p>\n<h3>Prerequisites<\/h3>\n<p>To process these Python data file formats, we need the library <em>pandas<\/em>.<\/p>\n<div id=\"attachment_20728\" style=\"width: 828px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20728\" class=\"wp-image-20728 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"818\" height=\"163\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1.png 818w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1-150x30.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1-300x60.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pandas-1-768x153.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/a><p id=\"caption-attachment-20728\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p>Install it using pip-<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; pip install pandas<\/pre>\n<h3>How to Read a CSV File in Python?<\/h3>\n<p>To read an entire file, rows, columns, or combinations of those, read on.<\/p>\n<div id=\"attachment_20743\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20743\" class=\"wp-image-20743 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01.jpg\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-CSV-File-in-Python-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-20743\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<h4>a. Reading an entire Python CSV File<\/h4>\n<p>To read an entire file, we can use the read_csv() function.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import pandas\r\n&gt;&gt;&gt; import os\r\n&gt;&gt;&gt; os.chdir('C:\\\\Users\\\\lifei\\\\Desktop')\r\n&gt;&gt;&gt; print(pandas.read_csv('schedule.csv'))<\/pre>\n<div id=\"attachment_20729\" style=\"width: 652px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20729\" class=\"wp-image-20729 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"642\" height=\"170\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv1.png 642w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv1-150x40.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv1-300x79.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><p id=\"caption-attachment-20729\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/python-tools\/\">Read about Python Tools \u2013 4 Major Utilities<\/a><\/p>\n<h4>b. Reading rows for one column<\/h4>\n<p>Sometimes, we may only want to fetch certain rows at once for a certain column. We use the slicing operator for this. Read up on <a href=\"https:\/\/data-flair.training\/blogs\/python-operators\/\"><strong>Python Operators<\/strong><\/a>.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; print(data[0:3]['title'])<\/pre>\n<div id=\"attachment_20730\" style=\"width: 376px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20730\" class=\"wp-image-20730 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv2.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"366\" height=\"119\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv2.png 366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv2-150x49.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv2-300x98.png 300w\" sizes=\"auto, (max-width: 366px) 100vw, 366px\" \/><\/a><p id=\"caption-attachment-20730\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<h4>c. Reading certain columns<\/h4>\n<p>Now we can also fetch only certain columns. For this, we use the .loc() method for multi-axis indexing.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; print(data.loc[:,['title','rating']])<\/pre>\n<div id=\"attachment_20731\" style=\"width: 514px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20731\" class=\"wp-image-20731 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv3.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"504\" height=\"170\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv3.png 504w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv3-150x51.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv3-300x101.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/a><p id=\"caption-attachment-20731\" class=\"wp-caption-text\">Python\u00a0CSV File\u00a0 &#8211; Reading certain columns<\/p><\/div>\n<h4>d. Reading certain rows and certain columns<\/h4>\n<p>Using the .loc() method, we can also fetch certain rows and certain columns:<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; print(data.loc[[1,3],['title','rating']])<\/pre>\n<div id=\"attachment_20732\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv4.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20732\" class=\"wp-image-20732 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv4.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"560\" height=\"99\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv4.png 560w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv4-150x27.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv4-300x53.png 300w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-20732\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<h4>e. Reading certain columns for a range of rows<\/h4>\n<p>Now to fetch certain columns for a range of rows, we slightly change the previous syntax and use slicing instead of indices.<\/p>\n<pre class=\"EnlighterJSRAW\">data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; print(data.loc[1:3,['title','rating']])<\/pre>\n<div id=\"attachment_20733\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv5.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20733\" class=\"wp-image-20733 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv5.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"530\" height=\"120\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv5.png 530w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv5-150x34.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readcsv5-300x68.png 300w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/a><p id=\"caption-attachment-20733\" class=\"wp-caption-text\">Python CSV File &#8211; Reading certain columns for a range of rows<\/p><\/div>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-generators\/\">Let&#8217;s revise Python Generators and Generator Expressions<\/a><\/strong><\/p>\n<h4>f. Using the Python CSV Module<\/h4>\n<p>You can also install the module CSV using pip, and then use the following code-<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import csv\r\n&gt;&gt;&gt; fields=rows=[]\r\n&gt;&gt;&gt; with open('schedule.csv','r') as file:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reader=csv.reader(file) #Reader object\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fields=next(reader)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for row in reader:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows.append(row)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(f\"You have {reader.line_num} rows\") #Number of rows\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\nYou have 6 rows\r\n&gt;&gt;&gt; print('\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 '.join(field for field in fields)) #Field names\r\nid\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 title\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timing\u00a0\u00a0 genre\u00a0\u00a0\u00a0 rating\r\n&gt;&gt;&gt; for row in rows[:6]:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for col in row:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(col)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print('\\n')<\/pre>\n<p>1<br \/>\nDog with a Blog<br \/>\n17:30-18:00<br \/>\nComedy<br \/>\n4.7<\/p>\n<p>2<br \/>\nLiv and Maddie<br \/>\n18:00-18:30<br \/>\nComedy<br \/>\n6.3<\/p>\n<p>3<br \/>\nGirl Meets World<br \/>\n18:30-19:00<br \/>\nComedy<br \/>\n7.2<\/p>\n<p>4<br \/>\nKC Undercover<br \/>\n19:00-19:30<br \/>\nComedy<br \/>\n6.1<\/p>\n<p>5<br \/>\nAustin and Ally<br \/>\n19:30-20:00<br \/>\nComedy<br \/>\n6<\/p>\n<h3>How to Read a JSON File in Python?<\/h3>\n<div id=\"attachment_20744\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20744\" class=\"wp-image-20744 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01.jpg\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-JSON-File-in-Python-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-20744\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files<\/p><\/div>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/python-decision-making-expressions\/\">Let&#8217;s Discuss Python Decision Making Statements\u00a0<\/a><\/strong><\/p>\n<h4>a. Reading an entire Python JSON file<\/h4>\n<p>To read an entire JSN file in Python, we can use the read_json() function.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import pandas\r\n&gt;&gt;&gt; print(pandas.read_csv('schedule.csv'))<\/pre>\n<div id=\"attachment_20734\" style=\"width: 664px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20734\" class=\"wp-image-20734 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"654\" height=\"174\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson1.png 654w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson1-150x40.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson1-300x80.png 300w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><p id=\"caption-attachment-20734\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read JSON Files<\/p><\/div>\n<h4>b. Reading certain rows and columns<\/h4>\n<p>And when you only want some rows and some columns, you can-<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; data.loc[[1,3],['title','rating']]<\/pre>\n<div id=\"attachment_20735\" style=\"width: 480px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20735\" class=\"wp-image-20735 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson2.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"470\" height=\"97\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson2.png 470w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson2-150x31.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson2-300x62.png 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/a><p id=\"caption-attachment-20735\" class=\"wp-caption-text\">Python JSON Files &#8211; Reading certain rows and columns<\/p><\/div>\n<h4>c. Reading rows and columns as records<\/h4>\n<p>You can also fetch the rows and columns as a sequence of records-<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_csv('schedule.csv')\r\n&gt;&gt;&gt; print(data.to_json(orient='records',lines=True))<\/pre>\n<div id=\"attachment_20736\" style=\"width: 985px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20736\" class=\"wp-image-20736 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"975\" height=\"268\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3.png 975w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3-150x41.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3-300x82.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readjson3-768x211.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/a><p id=\"caption-attachment-20736\" class=\"wp-caption-text\">Python JSON File &#8211; Reading rows and columns as records<\/p><\/div>\n<h3>How to Read an XLS File in Python?<\/h3>\n<p>Finally, let\u2019s find out how to read Python XLS files.<\/p>\n<div id=\"attachment_20745\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20745\" class=\"wp-image-20745 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01.jpg\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Reading-XLS-File-in-Python-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-20745\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read JSON File in Python<\/p><\/div>\n<h4>a. Reading an entire file<\/h4>\n<p>You can read an entire file using the read_excel() function.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import pandas\r\n&gt;&gt;&gt; print(pandas.read_excel('schedule.xlsx'))<\/pre>\n<div id=\"attachment_20737\" style=\"width: 652px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20737\" class=\"wp-image-20737 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls1.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"642\" height=\"167\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls1.png 642w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls1-150x39.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls1-300x78.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><p id=\"caption-attachment-20737\" class=\"wp-caption-text\">Python Data File Formats &#8211; How to Read XLS Files<\/p><\/div>\n<p><strong>Note- You may need to install a module for this-<\/strong><br \/>\nC:\\Users\\lifei&gt;pip install xlrd<br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-sets-and-booleans-with-syntax-and-examples\/\">Have a Look Python Sets and Booleans with Syntax and Examples<\/a><\/strong><\/p>\n<h4>b. Reading certain rows and columns<\/h4>\n<p>When you only want to fetch certain rows and columns, you can use the .loc() method.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; data=pandas.read_excel('schedule.xlsx')\r\n&gt;&gt;&gt; print(data.loc[[1,3],['title','rating']])<\/pre>\n<div id=\"attachment_20738\" style=\"width: 561px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20738\" class=\"wp-image-20738 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls2.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"551\" height=\"101\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls2.png 551w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls2-150x27.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls2-300x55.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/a><p id=\"caption-attachment-20738\" class=\"wp-caption-text\">Python XLS File &#8211; Reading certain rows and columns<\/p><\/div>\n<h4>c. Reading more than one sheet<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; with pandas.ExcelFile('schedule.xlsx') as book:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s1=pandas.read_excel(book,'Sheet1')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s2=pandas.read_excel(book,'Sheet2')<\/pre>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; s1[0:5]['title']\r\n<\/pre>\n<div id=\"attachment_20739\" style=\"width: 335px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20739\" class=\"wp-image-20739 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls3.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"325\" height=\"147\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls3.png 325w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls3-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls3-300x136.png 300w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/a><p id=\"caption-attachment-20739\" class=\"wp-caption-text\">Python XLS File &#8211; Reading more than one sheet<\/p><\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; s2[0:5]['years']<\/pre>\n<div id=\"attachment_20740\" style=\"width: 337px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls4.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20740\" class=\"wp-image-20740 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls4.png\" alt=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files\" width=\"327\" height=\"148\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls4.png 327w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls4-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/readxls4-300x136.png 300w\" sizes=\"auto, (max-width: 327px) 100vw, 327px\" \/><\/a><p id=\"caption-attachment-20740\" class=\"wp-caption-text\">Python XLS File &#8211; Reading more than one sheet<\/p><\/div>\n<h4>d. Using the Python XLRD Module<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import xlrd\r\n&gt;&gt;&gt; book=xlrd.open_workbook('schedule.xlsx')\r\n&gt;&gt;&gt; sheet=book.sheet_by_index(0)\r\n&gt;&gt;&gt; sheet.cell_value(0,0) #Value at cell at row 0 and column 0\r\n'id'\r\n&gt;&gt;&gt; sheet.nrows #Number of rows\r\n6\r\n&gt;&gt;&gt; sheet.ncols #Number of columns\r\n5\r\n&gt;&gt;&gt; for i in range(sheet.ncols):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sheet.cell_value(0,i) #Column names\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n'id'\r\n'title'\r\n'timing'\r\n'genre'\r\n'rating'\r\n&gt;&gt;&gt; sheet.row_values(1) #First row\r\n[1.0, 'Dog with a Blog', '17:30-18:00', 'Comedy', 4.7]<\/pre>\n<p>So, this was all about Python Data File Formats. Hope you like our explanation.<\/p>\n<h3>Conclusion<\/h3>\n<p>Hence, in this tutorial, we discussed different types of Python Data File Formats. In addition, we also learned how to process\/read formats like CSV, JSON, and XLS files in Python. Leave your comments below, and don\u2019t forget to visit again for another tutorial tomorrow.<\/p>\n<p>CSV files are the most common format and are easy to work with using Python. They store tabular data with values separated by commas. You can read them with Pandas and perform sorting, grouping, and plotting directly. Excel files may contain multiple sheets or formulas. Python lets you read specific sheets, write to new ones, or convert between CSV and XLS formats using packages like openpyxl or xlrd.<\/p>\n<p>See Also &#8211; <strong><a href=\"https:\/\/data-flair.training\/blogs\/recursion-in-python\/\">Recursion in Python with Examples<\/a><\/strong><br \/>\n<strong><a href=\"https:\/\/docs.python.org\/2\/library\/fileformats.html\">For reference<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last python tutorial, we studied\u00a0How to Work with Relational Database with Python. In this tutorial, we will discuss different types of Python Data File Formats: Python\u00a0CSV, JSON, and\u00a0XLS. Moreover, we will discuss&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":20742,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[10452,10630,10929,11357,11374,11379,11380,11383,11386,15305,15307],"class_list":["post-20709","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-csv","tag-python-json","tag-python-xls","tag-read-csv-python","tag-reading-csv-file-in-python","tag-reading-json-file-in-python","tag-reading-more-than-one-sheet","tag-reading-rows-for-one-column","tag-reading-xls-file-in-python","tag-using-the-csv-module","tag-using-the-xlrd-module"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Data File Formats - How to Read CSV, JSON, and XLS Files - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Data File Formats - How to Read Python CSV, JSON, XLS Files, xlrd module, reading entire Python CSV File &amp; Column wise file in python\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Data File Formats - How to Read CSV, JSON, and XLS Files - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Data File Formats - How to Read Python CSV, JSON, XLS Files, xlrd module, reading entire Python CSV File &amp; Column wise file in python\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-11T04:10:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-20T10:49:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Data File Formats - How to Read CSV, JSON, and XLS Files - DataFlair","description":"Python Data File Formats - How to Read Python CSV, JSON, XLS Files, xlrd module, reading entire Python CSV File & Column wise file in python","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:\/\/data-flair.training\/blogs\/python-data-file-formats\/","og_locale":"en_US","og_type":"article","og_title":"Python Data File Formats - How to Read CSV, JSON, and XLS Files - DataFlair","og_description":"Python Data File Formats - How to Read Python CSV, JSON, XLS Files, xlrd module, reading entire Python CSV File & Column wise file in python","og_url":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-11T04:10:22+00:00","article_modified_time":"2026-04-20T10:49:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files","datePublished":"2018-07-11T04:10:22+00:00","dateModified":"2026-04-20T10:49:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/"},"wordCount":1382,"commentCount":4,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg","keywords":["Python CSV","Python JSON","Python XLS","read csv python","Reading CSV File in Python","Reading JSON File in Python","Reading more than one sheet","Reading rows for one column","Reading XLS File in Python","Using the csv module","Using the xlrd module"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/","url":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/","name":"Python Data File Formats - How to Read CSV, JSON, and XLS Files - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg","datePublished":"2018-07-11T04:10:22+00:00","dateModified":"2026-04-20T10:49:01+00:00","description":"Python Data File Formats - How to Read Python CSV, JSON, XLS Files, xlrd module, reading entire Python CSV File & Column wise file in python","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-data-file-formats\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Data-File-Formats-01.jpg","width":1200,"height":628,"caption":"Python Data File Formats - How to Read CSV, JSON, and XLS Files"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Data File Formats &#8211; How to Read CSV, JSON, and XLS Files"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/20709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=20709"}],"version-history":[{"count":11,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/20709\/revisions"}],"predecessor-version":[{"id":147724,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/20709\/revisions\/147724"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/20742"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=20709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=20709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=20709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}