{"id":35,"date":"2017-06-05T16:08:46","date_gmt":"2017-06-05T21:08:46","guid":{"rendered":"http:\/\/1uslchriston.ad.here.com:8080\/blog\/?p=35"},"modified":"2017-08-11T15:34:47","modified_gmt":"2017-08-11T20:34:47","slug":"pandas-how-to-see-the-variety-of-values-in-a-dataframe-column","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/06\/05\/pandas-how-to-see-the-variety-of-values-in-a-dataframe-column\/","title":{"rendered":"Pandas: How to see the variety of values in a DataFrame column"},"content":{"rendered":"<p>To see the variety of values in an individual column of your DataFrame, you can use the name of the DataFrame column (in this case &#8216;Y&#8217;) and place it into a set, then print the values in the set. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># Check the variety of values in the Y column\r\nprop_variety = set(my_dataframe[\"Y\"])\r\nprop_variety<\/pre>\n<p>which yields:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">{0, 1}<\/pre>\n<p>For the case of seeing the variety of values for <em>every<\/em> column in the DataFrame, I wrote a function that will print each column label followed by the variety of values in each column. You just pass it the name of the DataFrame. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def view_column_variety(df):\r\n    \"\"\"See the variety of values held in each column.\"\"\"\r\n    header_list = list(df.columns.values)\r\n    for prop in header_list:\r\n        prop_variety = set(df[prop])\r\n        print(prop)\r\n        print(prop_variety, \"\\n\")<\/pre>\n<p>Then call it like so:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">view_column_variety(my_dataframe)<\/pre>\n<p>Example of output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-theme=\"mootools\" data-enlighter-language=\"no-highlight\">layerObject:properties:dir\r\n{'T', 'F', 'B'} \r\n\r\nlayerObject:properties:fc\r\n{1, 2, 3, 4, 5, 6} \r\n\r\nlayerObject:properties:laneCat\r\n{1, 2, 3} \r\n\r\nlayerObject:properties:lanes\r\n{'1', 'None'} \r\n\r\nlayerObject:properties:nmc_roadtype\r\n{'6', '1', '5', 'None', '2', '3'} \r\n\r\nlayerObject:properties:pc\r\n{'6', '1', 'None', '0', '5', '4', '2', '3', '7', '8'} \r\n\r\nlayerObject:properties:roadQuality\r\n{'0', '1', 'None'} \r\n\r\nlayerObject:properties:speedCat\r\n{1, 2, 3, 4, 5, 6, 7, 8}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To see the variety of values in an individual column of your DataFrame, you can use the name of the DataFrame column (in this case &#8216;Y&#8217;) and place it into a set, then print the values in the set. For example: # Check the variety of values in the Y column prop_variety = set(my_dataframe[&#8220;Y&#8221;]) prop_variety &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/06\/05\/pandas-how-to-see-the-variety-of-values-in-a-dataframe-column\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Pandas: How to see the variety of values in a DataFrame column<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[6,3,4],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-pandas","tag-dataframe","tag-pandas","tag-python"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":13,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/35\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}