{"id":11037,"date":"2018-11-24T18:20:34","date_gmt":"2018-11-24T15:20:34","guid":{"rendered":"https:\/\/railsware.com\/blog\/?p=11037"},"modified":"2021-08-17T11:00:48","modified_gmt":"2021-08-17T08:00:48","slug":"python-for-machine-learning-pandas-axis-explained","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/","title":{"rendered":"Python for Machine Learning: Pandas Axis Explained"},"content":{"rendered":"\n<p class=\"intro-text wp-block-paragraph\">Pandas is a powerful library in a toolbox for every Machine Learning engineer. It provides two main data structures: <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/generated\/pandas.Series.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Series<\/a> and <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/generated\/pandas.DataFrame.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DataFrame<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many API calls of these types accept cryptical &#8220;axis&#8221; parameter. This parameter is poorly described in Pandas\u2019 documentation, though it has a key significance for using the library efficiently. The goal of the article is to fill in this gap and to provide a solid understanding of what the &#8220;axis&#8221; parameter is and how to use it in various use cases including leading-edge <a href=\"https:\/\/railsware.com\/services\/ai-machine-learning-consulting\/\" target=\"_blank\" rel=\"noopener noreferrer\">artificial intelligence applications<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"2400\" height=\"1260\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-illustration.jpg\" alt=\"Pandas Axis Usage in Machine Learning\" class=\"wp-image-11106\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-illustration.jpg 2400w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-illustration-360x189.jpg 360w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-illustration-768x403.jpg 768w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-illustration-1024x538.jpg 1024w\" sizes=\"auto, (max-width: 2400px) 100vw, 2400px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Axis in Series<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Series<\/em> is a one-dimensional array of values. Under the hood, it uses <a href=\"https:\/\/www.numpy.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">NumPy<\/a> <a href=\"https:\/\/www.numpy.org\/devdocs\/reference\/arrays.ndarray.html\">ndarray<\/a>. That is where the term &#8220;axis&#8221; came from. <em>NumPy<\/em> uses it quite frequently because <em>ndarray<\/em> can have a lot of dimensions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Series<\/em> object has only &#8220;axis 0&#8221; because it has only one dimension.<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11041\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/pandas-series-axis.png\" alt=\"\" width=\"1138\" height=\"486\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/pandas-series-axis.png 1138w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/pandas-series-axis-360x154.png 360w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/pandas-series-axis-768x328.png 768w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/pandas-series-axis-1024x437.png 1024w\" sizes=\"auto, (max-width: 1138px) 100vw, 1138px\" \/><br>The arrow on the image displays &#8220;axis 0&#8221; and its direction for the <em>Series<\/em> object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually, in Python, one-dimensional structures are displayed as a row of values. On the contrary, here we see that <em>Series<\/em> is displayed as a column of values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each cell in <em>Series<\/em> is accessible via index value along the &#8220;axis 0&#8221;. For our <em>Series<\/em> object indexes are: 0, 1, 2, 3, 4. Here is an example of accessing different values:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> srs = pd.Series(['red', 'green', 'blue', 'white', 'black'])\n>>> srs[0]\n'red'\n>>> srs[3]\n'white'\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Axes in DataFrame<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>DataFrame<\/em> is a two-dimensional data structure akin to SQL table or Excel spreadsheet. It has columns and rows. Its columns are made of separate <em>Series<\/em> objects. Let&#8217;s see an example:<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11040\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/data-frame-axes.png\" alt=\"\" width=\"1172\" height=\"634\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/data-frame-axes.png 1172w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/data-frame-axes-360x195.png 360w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/data-frame-axes-768x415.png 768w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/data-frame-axes-1024x554.png 1024w\" sizes=\"auto, (max-width: 1172px) 100vw, 1172px\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <em>DataFrame<\/em> object has two axes: &#8220;axis 0&#8221; and &#8220;axis 1&#8221;. &#8220;axis 0&#8221; represents rows and &#8220;axis 1&#8221; represents columns. Now it&#8217;s clear that <em>Series<\/em> and <em>DataFrame<\/em> share the same direction for &#8220;axis 0&#8221; &#8211; it goes along rows direction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our <em>DataFrame<\/em> object has 0, 1, 2, 3, 4 indexes along the &#8220;axis 0&#8221;, and additionally, it has &#8220;axis 1&#8221; indexes which are: <em>&#8216;a&#8217;<\/em> and <em>&#8216;b&#8217;<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To access an element within <em>DataFrame<\/em> we need to provide two indexes (one per each axis). Also, instead of bare brackets, we need to use <em>.loc<\/em> method:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> srs_a = pd.Series([1,3,6,8,9])\n>>> srs_b = pd.Series(['red', 'green', 'blue', 'white', 'black'])\n>>> df = pd.DataFrame({'a': srs_a, 'b': srs_b})\n>>> df.loc[2, 'b']\n'blue'\n>>> df.loc[3, 'a']\n8\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using \u201caxis\u201d parameter in API calls<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are a lot of different API calls for <a href=\"\/\/pandas.pydata.org\/pandas-docs\/stable\/generated\/pandas.Series.html\u201d\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Series<\/a> and <a href=\"\/\/pandas.pydata.org\/pandas-docs\/stable\/generated\/pandas.DataFrame.html\u201d\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DataFrame<\/a> objects which accept &#8220;axis&#8221; parameter. <em>Series<\/em> object has only one axis, so this parameter always equals <em> 0 <\/em> for it. Thus, you can omit it, because it does not affect the result:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> srs = pd.Series([1, 3, pd.np.nan, 4, pd.np.nan])\n>>> srs.dropna()\n0    1.0\n1    3.0\n3    4.0\ndtype: float64\n>>> srs.dropna(axis=0)\n0    1.0\n1    3.0\n3    4.0\ndtype: float64\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the contrary, <em>DataFrame<\/em> has two axes, and &#8220;axis&#8221; parameter determines along which axis an operation should be performed. For example, <em>.sum<\/em> can be applied along &#8220;axis 0&#8221;. That means, <em>.sum<\/em> operation calculates a sum for each column:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> srs_a = pd.Series([10,30,60,80,90])\n>>> srs_b = pd.Series([22, 44, 55, 77, 101])\n>>> df = pd.DataFrame({'a': srs_a, 'b': srs_b})\n>>> df\n    a    b\n0  10   22\n1  30   44\n2  60   55\n3  80   77\n4  90  101\n>>> df.sum(axis=0)\na    270\nb    299\ndtype: int64\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We see, that having sum with <em>axis=0<\/em> smashed all values along the direction of the &#8220;axis 0&#8221; and left only columns(<em>&#8216;a&#8217;<\/em> and <em>&#8216;b&#8217;<\/em>) with appropriate sums.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With <em>axis=1<\/em> it produces a sum for each row:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> df.sum(axis=1)\n0     32\n1     74\n2    115\n3    157\n4    191\ndtype: int64\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer regular names instead of numbers, each axis has a string alias. &#8220;axis 0&#8221; has two aliases: <em>&#8216;index&#8217;<\/em> and <em>&#8216;rows&#8217;<\/em>. &#8220;axis 1&#8221; has only one: <em>&#8216;columns&#8217;<\/em>. You can use these aliases instead of numbers:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> df.sum(axis='index')\na    270\nb    299\ndtype: int64\n>>> df.sum(axis='rows')\na    270\nb    299\ndtype: int64\n>>> df.sum(axis='columns')\n0     32\n1     74\n2    115\n3    157\n4    191\ndtype: int64\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Dropping NaN values<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build a simple <em>DataFrame<\/em> with <em>NaN<\/em> values and observe how axis affects <em>.dropna<\/em> method:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> import numpy as np\n>>> df = pd.DataFrame({'a': [2, np.nan, 8, 3], 'b': [np.nan, 32, 15, 7], 'c': [-3, 5, 22, 19]})\n>>> df\n     a     b   c\n0  2.0   NaN  -3\n1  NaN  32.0   5\n2  8.0  15.0  22\n3  3.0   7.0  19\n>>> df.dropna(axis=0)\n     a     b   c\n2  8.0  15.0  22\n3  3.0   7.0  19\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <em>.dropna<\/em> filters out any row(we are moving along &#8220;axis 0&#8221;) which contains <em>NaN<\/em> value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s use &#8220;axis 1&#8221; direction:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> df.dropna(axis=1)\n    c\n0  -3\n1   5\n2  22\n3  19\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now <em>.dropna<\/em> collapsed &#8220;axis 1&#8221; and removed all columns with <em>NaN<\/em> values. Columns <em>&#8216;a&#8217;<\/em> and <em>&#8216;b&#8217;<\/em> contained <em>NaN<\/em> values, thus only <em>&#8216;c&#8217;<\/em> column was left.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Concatenation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Concatenation function with <em>axis=0<\/em> stacks the first <em>DataFrame<\/em> over the second:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\n>>> df1 = pd.DataFrame({'a': [1,3,6,8,9], 'b': ['red', 'green', 'blue', 'white', 'black']})\n>>> df2 = pd.DataFrame({'a': [0,2,4,5,7], 'b': ['jun', 'jul', 'aug', 'sep', 'oct']})\n>>> pd.concat([df1, df2], axis=0)\n   a      b\n0  1    red\n1  3  green\n2  6   blue\n3  8  white\n4  9  black\n0  0    jun\n1  2    jul\n2  4    aug\n3  5    sep\n4  7    oct\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With <em>axis=1<\/em> both DataFrames are put along each other:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> pd.concat([df1, df2], axis=1)\n   a      b  a    b\n0  1    red  0  jun\n1  3  green  2  jul\n2  6   blue  4  aug\n3  8  white  5  sep\n4  9  black  7  oct\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Pandas<\/em> borrowed the &#8220;axis&#8221; concept from <em>NumPy<\/em> library. The &#8220;axis&#8221; parameter does not have any influence on a <em>Series<\/em> object because it has only one axis. On the contrary, <em>DataFrame<\/em> API heavily relies on the parameter, because it&#8217;s a two-dimensional data structure, and many operations can be performed along different axes producing totally different results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases<\/p>\n","protected":false},"author":25,"featured_media":11105,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Sergii Boiko"],"class_list":["post-11037","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Sergii Boiko\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Python for Machine Learning: Pandas Axis Explained | Railsware Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2018-11-24T15:20:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-08-17T08:00:48+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#article\",\"name\":\"Python for Machine Learning: Pandas Axis Explained | Railsware Blog\",\"headline\":\"Python for Machine Learning: Pandas Axis Explained\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/11\\\/PythonMLPandas-icon.png\",\"width\":360,\"height\":360,\"caption\":\"Pandas Axis for Machine Learning\"},\"datePublished\":\"2018-11-24T18:20:34+03:00\",\"dateModified\":\"2021-08-17T11:00:48+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#webpage\"},\"articleSection\":\"Engineering\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#listItem\",\"name\":\"Python for Machine Learning: Pandas Axis Explained\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#listItem\",\"position\":3,\"name\":\"Python for Machine Learning: Pandas Axis Explained\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/\",\"name\":\"Sergii Boiko\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/sergii-boiko-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"Sergii Boiko\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/\",\"name\":\"Python for Machine Learning: Pandas Axis Explained | Railsware Blog\",\"description\":\"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \\u201caxis\\u201d parameter and how to use it in various cases\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/11\\\/PythonMLPandas-icon.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#mainImage\",\"width\":360,\"height\":360,\"caption\":\"Pandas Axis for Machine Learning\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/python-for-machine-learning-pandas-axis-explained\\\/#mainImage\"},\"datePublished\":\"2018-11-24T18:20:34+03:00\",\"dateModified\":\"2021-08-17T11:00:48+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Python for Machine Learning: Pandas Axis Explained | Railsware Blog","description":"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases","canonical_url":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#article","name":"Python for Machine Learning: Pandas Axis Explained | Railsware Blog","headline":"Python for Machine Learning: Pandas Axis Explained","author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png","width":360,"height":360,"caption":"Pandas Axis for Machine Learning"},"datePublished":"2018-11-24T18:20:34+03:00","dateModified":"2021-08-17T11:00:48+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#webpage"},"articleSection":"Engineering"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#listItem","name":"Python for Machine Learning: Pandas Axis Explained"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#listItem","position":3,"name":"Python for Machine Learning: Pandas Axis Explained","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author","url":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/","name":"Sergii Boiko","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/sergii-boiko-96x96.jpg","width":96,"height":96,"caption":"Sergii Boiko"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#webpage","url":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/","name":"Python for Machine Learning: Pandas Axis Explained | Railsware Blog","description":"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png","@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#mainImage","width":360,"height":360,"caption":"Pandas Axis for Machine Learning"},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/#mainImage"},"datePublished":"2018-11-24T18:20:34+03:00","dateModified":"2021-08-17T11:00:48+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"Python for Machine Learning: Pandas Axis Explained | Railsware Blog","og:description":"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases","og:url":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png","og:image:width":360,"og:image:height":360,"article:published_time":"2018-11-24T15:20:34+00:00","article:modified_time":"2021-08-17T08:00:48+00:00"},"aioseo_meta_data":{"post_id":"11037","title":null,"description":"Pandas, a powerful library for Python, is a must-have tool for every machine learning developer. Check out the hands-on explanation of the Pandas \u201caxis\u201d parameter and how to use it in various cases","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6385f59f1148f","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"email":"","phone":"","phoneFormatted":"","fax":"","faxFormatted":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-04 12:44:38","updated":"2025-09-26 11:29:39","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPython for Machine Learning: Pandas Axis Explained\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"Python for Machine Learning: Pandas Axis Explained","link":"https:\/\/railsware.com\/blog\/python-for-machine-learning-pandas-axis-explained\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2018\/11\/PythonMLPandas-icon.png","article_background":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/11037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=11037"}],"version-history":[{"count":20,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/11037\/revisions"}],"predecessor-version":[{"id":14219,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/11037\/revisions\/14219"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/11105"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=11037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=11037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=11037"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=11037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}