{"id":7643,"date":"2025-04-08T06:28:11","date_gmt":"2025-04-08T06:28:11","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7643"},"modified":"2025-04-08T06:28:14","modified_gmt":"2025-04-08T06:28:14","slug":"how-to-convert-pandas-dataframe-to-dictionary","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/","title":{"rendered":"How to Convert Pandas Dataframe to Dictionary"},"content":{"rendered":"\n<p>Python Pandas is a powerful library that allows you to store and manipulate data as columns and rows, using dataframes. It also provides many useful functions to convert different data types into dataframes, or even export data into dataframes. But sometimes, you may need to convert dataframe to dictionary. In this article, we will how to convert Pandas dataframe to dictionary.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of 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: #999;color:#999\" 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: #999;color:#999\" 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 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#Why_Convert_Dataframe_to_Dictionary\" >Why Convert Dataframe to Dictionary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#How_to_Convert_Pandas_Dataframe_to_Dictionary\" >How to Convert Pandas Dataframe to Dictionary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#About_to_dict\" >About to_dict<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#1_Using_dict_option\" >1. Using dict option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#2_Using_list_option\" >2. Using list option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#3_Using_series_option\" >3. Using series option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#4_Using_split_option\" >4. Using split option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#5_Using_records_option\" >5. Using records option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#6_Using_index_option\" >6. Using index option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#Advantages_of_converting_dataframe_to_dict\" >Advantages of converting dataframe to dict<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#Disadvantages_of_converting_dataframe_to_dict\" >Disadvantages of converting dataframe to dict<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#Possible_Errors_in_converting_dataframe_to_dict\" >Possible Errors in converting dataframe to dict<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#FAQs\" >FAQs<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Convert_Dataframe_to_Dictionary\"><\/span>Why Convert Dataframe to Dictionary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are several reasons why you may need to convert dataframe to dictionary:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Dictionary data types can be easily converted into JSON and vice versa. So sometimes, you may need to convert a dataframe to dictionary<\/li>\n\n\n\n<li>Dictionary allows you to easily access data using keys. It is especially useful if you have nested data. In such cases, you may need to convert dataframe to dictionary.<\/li>\n\n\n\n<li>Sometimes external systems and processes may require you to send data as dictionary. In such cases, it is convenient to convert dataframe to dictionary.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Convert_Pandas_Dataframe_to_Dictionary\"><\/span>How to Convert Pandas Dataframe to Dictionary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us look at the different ways to convert Pandas dataframe to dictionary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"About_to_dict\"><\/span>About to_dict<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We will mainly use to_dict function to convert dataframe into dictionary. It can be directly called from any dataframe object and allows you to transform dataframe into different types of data such as dictionary, list, series, etc. It has <em>orient<\/em> parameter that accepts different values that determine the format of result. They are covered below one by one.<\/p>\n\n\n\n<p>Let us say you have the following dataframe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>data = {'Name': ['John', 'Jane', 'Jim', 'Joe'],<br>        'Age': [28, 24, 25, 22],<br>        'City': ['New York', 'Paris', 'Berlin', 'London']}<br><br>df = pd.DataFrame(data)<br>print(df)<br><br>## output <br><br>   Name  Age      City<br>0  John   28  New York<br>1  Jane   24     Paris<br>2   Jim   25    Berlin<br>3   Joe   22    London<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_dict_option\"><\/span>1. Using dict option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The default orient parameter value is dict and it will convert dataframe into dictionary with index as keys and corresponding values. Even if you do not specify any orient value, still to_dict will use this option.<\/p>\n\n\n\n<p>Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dataframe.to_dict('dict')<br>OR<br>dataframe.to_dict()<\/pre>\n\n\n\n<p>Here is an example to demonstrate its use.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict()<br>print(dt)<br><br>## output<br><br>{'Name': {0: 'John', 1: 'Jane', 2: 'Jim', 3: 'Joe'}, 'Age': {0: 28, 1: 24, 2: 25, 3: 22}, 'City': {0: 'New York', 1: 'Paris', 2: 'Berlin', 3: 'London'}}<\/pre>\n\n\n\n<p>The above result is a nested dict. The outermost keys are the column names. The keys of inner dict are the indexes and the final values of these keys are the dataframe column values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_list_option\"><\/span>2. Using list option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you use this option, the column names will be keys and the column values will become the lists.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict('list')<br>print(dt)<br><br>## output <br><br>{'Name': ['John', 'Jane', 'Jim', 'Joe'], 'Age': [28, 24, 25, 22], 'City': ['New York', 'Paris', 'Berlin', 'London']}<br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_series_option\"><\/span>3. Using series option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you use this option, column names are keys and column values are series of column values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict('series')<br>print(dt)<br><br>## output<br><br>{'Name': 0    John<br>1    Jane<br>2     Jim<br>3     Joe<br>Name: Name, dtype: object, 'Age': 0    28<br>1    24<br>2    25<br>3    22<br>Name: Age, dtype: int64, 'City': 0    New York<br>1       Paris<br>2      Berlin<br>3      London<br>Name: City, dtype: object}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_split_option\"><\/span>4. Using split option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this case, the result dict will contain 3 keys &#8211; index, columns and data. The first key&#8217;s value is a list of all indexes. The second key&#8217;s value is a list of all column names. The third key&#8217;s value is a nested list where each inner list is a list of row values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict('split')<br>print(dt)<br><br>## output<br><br>{'index': [0, 1, 2, 3], 'columns': ['Name', 'Age', 'City'], 'data': [['John', 28, 'New York'], ['Jane', 24, 'Paris'], ['Jim', 25, 'Berlin'], ['Joe', 22, 'London']]}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_records_option\"><\/span>5. Using records option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you use this option, to_dict will return a list of dictionaries. In each dictionary, the keys are column names and the values are column values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict('records')<br>print(dt)<br><br>## output<br><br>[{'Name': 'John', 'Age': 28, 'City': 'New York'}, {'Name': 'Jane', 'Age': 24, 'City': 'Paris'}, {'Name': 'Jim', 'Age': 25, 'City': 'Berlin'}, {'Name': 'Joe', 'Age': 22, 'City': 'London'}]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_index_option\"><\/span>6. Using index option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With this option, you get a nested dictionary, where outer keys are indexes. The inner dictionary keys are column names and final values are the column values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dt=df.to_dict('index')<br>print(dt)<br><br>## output<br><br>{0: {'Name': 'John', 'Age': 28, 'City': 'New York'}, 1: {'Name': 'Jane', 'Age': 24, 'City': 'Paris'}, 2: {'Name': 'Jim', 'Age': 25, 'City': 'Berlin'}, 3: {'Name': 'Joe', 'Age': 22, 'City': 'London'}}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advantages_of_converting_dataframe_to_dict\"><\/span>Advantages of converting dataframe to dict<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the main benefits of transforming dataframe into dict. <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Dictionary is a much simpler data structure than dataframe. It allows you to easily store and access tabular data using key-value pairs. This can be useful if you are dealing with large data sets that require frequent read operations. Also, dictionary is more suitable for nested data.<\/li>\n\n\n\n<li>Since you can directly access data using its key, you can easily manipulate it as per your requirement. It is easier to modify data in a dictionary compared to doing so with a dataframe.<\/li>\n\n\n\n<li>Certain programs and processes may require input data as dictionary. In such cases, it is better to convert dataframe into dict.<\/li>\n\n\n\n<li>Dictionary is more memory efficient than dataframe, since it does not take up much space to store data, and it does not contain much metadata. On the other hand, dataframes take up more space. If you need to optimize the memory utilization of your Python program, then you can convert dataframe into dict.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Disadvantages_of_converting_dataframe_to_dict\"><\/span>Disadvantages of converting dataframe to dict<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>On the other hand, there are certain disadvantages to converting dataframe to dict.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>When you convert dataframe to dict, then the index information used to optimize dataframe access is lost. If your program heavily relies on dataframe indexes, then it will slow down since dictionaries do not support indexes. However, their key-value structure allows you to quickly access data too.<\/li>\n\n\n\n<li>Dataframes allow you to label data using column names. They also allow you to get data type information for columns. Dictionary lack both these features<\/li>\n\n\n\n<li>While converting dataframe into dict, in most cases, column names are converted into keys. Sometimes you may end up with redundant data, in case the same column name has to be repeated multiple times. So in some cases, the dictionary may be bulkier than its dataframe.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Possible_Errors_in_converting_dataframe_to_dict\"><\/span>Possible Errors in converting dataframe to dict<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We have to be careful about the following things while converting dataframe to dict:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The to_dict function only accepts specific values for orient argument. If you pass an invalid argument or value for orient parameter, then it will result in an error.<\/li>\n\n\n\n<li>If any of the dataframe columns contains mixed data-type then it will result in an error. So before you call to_dict function, it is important to ensure that the columns contain consistent data types.<\/li>\n\n\n\n<li>If the dataframe contains NaN or missing values then conversion to dictionary may cause problems. It may give an error or result in unexpected values in dictionary. So it is good to look for missing or NaN values and replace them before you convert dataframe into dict.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to easily convert Pandas dataframe into dictionary. Mainly, we need to use to_dict() function with appropriate orient parameter value. Depending on your requirement, you can use any of these options. It is important to use the right orient parameter value depending on how you want to organize dataframe data into dictionary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>1. How to Convert Dataframe into Dictionary where each row&#8217;s values are stored as a separate dictionary?<\/strong><\/p>\n\n\n\n<p>You can use to_dict() function with orient parameter value set to &#8216;records&#8217;. In this case, you will get a list of dictionaries, where each dictionary contains a separate dataframe row&#8217;s values.<\/p>\n\n\n\n<p><strong>2. How to exclude index values from dataframe in dictionary?<\/strong><\/p>\n\n\n\n<p>For this purpose, you can use to_dict function with orient parameter as list or records option.<\/p>\n\n\n\n<p><strong>3. How to include index values from dataframe in dictionary?<\/strong><\/p>\n\n\n\n<p>There are several options to include index values from dataframe. The default option or dict option for orient parameter will return a nested dictionary where outer keys are column values and inner keys are index values.<\/p>\n\n\n\n<p>If you use index option, then also you get a nested dict but in this case, the outer key is index and the inner key is column name.<\/p>\n\n\n\n<p>If you use series option, then the keys will be column names and the values will be index followed by column value.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-list\/\">How to Convert Pandas Dataframe to List<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\">How to Compare Two Lists in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-create-dictionary-from-lists-in-python\/\">How to Create Dictionary from Lists<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.<\/p>\n","protected":false},"author":1,"featured_media":7680,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[406],"class_list":["post-7643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-dataframe-to-dictionary"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Convert Pandas Dataframe to Dictionary - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Convert Pandas Dataframe to Dictionary - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-08T06:28:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-08T06:28:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"301\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Convert Pandas Dataframe to Dictionary\",\"datePublished\":\"2025-04-08T06:28:11+00:00\",\"dateModified\":\"2025-04-08T06:28:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/\"},\"wordCount\":1190,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1\",\"keywords\":[\"dataframe to dictionary\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/\",\"name\":\"How to Convert Pandas Dataframe to Dictionary - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1\",\"datePublished\":\"2025-04-08T06:28:11+00:00\",\"dateModified\":\"2025-04-08T06:28:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1\",\"width\":301,\"height\":200,\"caption\":\"convert pandas dataframe to dict\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-convert-pandas-dataframe-to-dictionary\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Convert Pandas Dataframe to Dictionary\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Convert Pandas Dataframe to Dictionary - Ubiq BI","description":"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.","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:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/","og_locale":"en_US","og_type":"article","og_title":"How to Convert Pandas Dataframe to Dictionary - Ubiq BI","og_description":"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-04-08T06:28:11+00:00","article_modified_time":"2025-04-08T06:28:14+00:00","og_image":[{"width":301,"height":200,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Convert Pandas Dataframe to Dictionary","datePublished":"2025-04-08T06:28:11+00:00","dateModified":"2025-04-08T06:28:14+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/"},"wordCount":1190,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1","keywords":["dataframe to dictionary"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/","name":"How to Convert Pandas Dataframe to Dictionary - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1","datePublished":"2025-04-08T06:28:11+00:00","dateModified":"2025-04-08T06:28:14+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often Python developers need to convert Pandas dataframe to dictionary. Here are the different ways to do this.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1","width":301,"height":200,"caption":"convert pandas dataframe to dict"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-convert-pandas-dataframe-to-dictionary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Convert Pandas Dataframe to Dictionary"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/convert-dataframe-to-dict.jpg?fit=301%2C200&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Zh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7643"}],"version-history":[{"count":36,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7643\/revisions"}],"predecessor-version":[{"id":7679,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7643\/revisions\/7679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7680"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}