

{"id":59216,"date":"2019-06-14T17:04:13","date_gmt":"2019-06-14T11:34:13","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=59216"},"modified":"2019-06-14T17:16:13","modified_gmt":"2019-06-14T11:46:13","slug":"aggregation-and-grouping-in-pandas","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/","title":{"rendered":"Aggregation and Grouping in Pandas explained by Experts"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1508,&quot;href&quot;:&quot;https:\\\/\\\/pandas.pydata.org\\\/pandas-docs\\\/stable\\\/reference\\\/api\\\/pandas.DataFrame.max.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250816035023\\\/https:\\\/\\\/pandas.pydata.org\\\/pandas-docs\\\/stable\\\/reference\\\/api\\\/pandas.DataFrame.max.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 09:42:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-17 06:06:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-09 08:37:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-12 16:32:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 00:44:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 09:51:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 12:17:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-25 17:44:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-03 13:53:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 03:49:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-19 08:10:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 07:37:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 19:30:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 14:59:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-08 06:07:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 15:35:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-17 10:34:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-24 12:29:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-01 09:43:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-14 14:10:37&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-14 14:10:37&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Pandas is popularly known as a <em>data analysis to<\/em>ol, which is offering a data manipulation library. With the help of this feature, we can analyze large data in an efficient manner. Here, we can apply common database operations like merging, aggregation, and grouping in Pandas.<\/p>\n<p>This article will provide you a bunch of information about aggregation &amp; grouping of data in Pandas. By the end of this article, you can apply sum(), max(), min(), mean(), and medium() functions on your dataframes.<\/p>\n<h2>Aggregation and Grouping in Pandas<\/h2>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59253\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg\" alt=\"Aggregation and Grouping in Pandas\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h3>1. Aggregation in Pandas<\/h3>\n<p><em>Pandas provide us with a variety of aggregate functions<\/em>. These functions help to perform various activities on the datasets. The functions are:<\/p>\n<ul>\n<li><strong>.count():<\/strong> This gives a count of the data in a column.<\/li>\n<li><strong>.sum():<\/strong> This gives the sum of data in a column.<\/li>\n<li><strong>.min() and .max():<\/strong> This helps to find the minimum value and maximum value, ina function, respectively.<\/li>\n<li><strong>.mean() and .median():<\/strong> Helps to find the mean and median, of the values in a column, respectively.<\/li>\n<\/ul>\n<p>First, we start by importing pandas as pd<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; import pandas as pd<\/pre>\n<p>Then we import a dataset:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df= pd.read_csv(\"https:\/\/opendata.socrata.com\/api\/views\/da8m-smts\/rows.csv?accessType=DOWNLOAD\")<\/pre>\n<p>This dataset is about car sales. We will enter our DataFrame name <strong>\u201cdataflair_df\u201d<\/strong> to see the dataset.<\/p>\n<p><em><strong>Before we move ahead I recommend to revise the concept of\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/pandas-dataframe\/\">Pandas Dataframe<\/a><\/strong><\/em><\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59237\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas.jpg\" alt=\"Create dataset in Pandas\" width=\"1365\" height=\"836\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas.jpg 1365w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas-150x92.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas-300x184.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas-768x470.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas-1024x627.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Create-dataset-in-Pandas-520x318.jpg 520w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/a><\/p>\n<h4>1.1 .count() function<\/h4>\n<p>To start off, the first function of aggregation that we are going to try is\u00a0<strong>.count()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.count()<\/pre>\n<p>Therefore, we see that the<strong> .count() function<\/strong> returns the number of entries for every column.<\/p>\n<p>If we want to count a particular column, then we use:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df[[\"Year\"]].count()<\/pre>\n<p>Or we use:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Year.count()<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59238\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas.jpg\" alt=\"Count function in Pandas\" width=\"1366\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas-150x81.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas-300x163.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas-768x416.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas-1024x555.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Count-function-in-Pandas-520x282.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>Both will yield the same result. The first one returns a <strong>Pandas DataFrame object<\/strong> and the second one returns a <strong><a href=\"https:\/\/data-flair.training\/blogs\/pandas-series\/\"><em>Pandas Series<\/em><\/a> object.<\/strong><\/p>\n<h4>1.2\u00a0.sum() function<\/h4>\n<p>We can use the<strong> .sum<\/strong> <strong>function<\/strong> to find the sum of elements in a column.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.sum()<\/pre>\n<p>But we do not always need to find the sum of all the columns. For only one column, we use:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Total.sum()<\/pre>\n<p>This will give us the sum of the values in the column Total.<\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59239\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas.jpg\" alt=\"Sum function in Pandas\" width=\"1366\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas-150x81.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas-300x163.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas-768x416.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas-1024x555.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Sum-function-in-Pandas-520x282.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>1.3.\u00a0min() and max() function<\/h4>\n<p>We can find the minimum and maximum values of the dataset using function<strong> min() and <\/strong><a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.DataFrame.max.html\">max() function<\/a><strong> in pandas<\/strong>:<\/p>\n<p>Use this code to find minimum value:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Total.min()<\/pre>\n<p>For finding the maximum value, we will use:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Total.max()<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59240\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas.jpg\" alt=\"min and max function in Pandas\" width=\"1366\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas-150x81.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas-300x163.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas-768x416.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas-1024x555.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/min-and-max-function-in-Pandas-520x282.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>1.4\u00a0mean() and median() function<\/h4>\n<p>The functions of the mean() and median() are to find the mean and median, as it can be seen.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Domestics.mean()<\/pre>\n<p>This is finding the mean or average of the column named \u201cDomestics\u201d<\/p>\n<p>We can find the median too:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.Domestics.median()<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59241\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas.jpg\" alt=\"\u00a0mean and median function in Pandas\" width=\"1366\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas-150x81.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas-300x163.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas-768x416.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas-1024x555.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/mean-and-median-function-in-Pandas-520x282.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>2. Grouping Function in Pandas<\/h3>\n<p><em>Grouping is an essential part of data analyzing in Pandas. We can group similar types of data and implement various functions on them.<\/em><\/p>\n<p>For grouping in Pandas, we will use the .<strong>groupby() function<\/strong> to group according to \u201cMonth\u201d and then find the mean:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.groupby(\"Month\").mean()<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59226\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas.jpg\" alt=\"Example of groupby function in Pandas\" width=\"1366\" height=\"744\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas-150x82.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas-300x163.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas-768x418.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas-1024x558.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/groupby-function-in-Pandas-520x283.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>Here, we saw that the months have been grouped and the mean of all their corresponding column has been calculated.<\/p>\n<p><em><strong>Do to know the difference between grouping\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/pandas-merge-and-join\/\">merging and joining in Pandas.<\/a><\/strong><\/em><\/p>\n<ul>\n<li><strong>But, if we want to find the mean of a single column of our choice, we will use:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.groupby(\"Month\").mean().Total<\/pre>\n<p>Where \u201cTotal\u201d can be replaced with any other column name too.<\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59227\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas.jpg\" alt=\"Find mean of a single column in Pandas\" width=\"1366\" height=\"694\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas-150x76.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas-300x152.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas-768x390.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas-1024x520.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Find-mean-of-a-single-column-in-Pandas-520x264.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>We can use the aggregate function to implement various functions like min, max, median, etc. all at once. The aggregate function also takes parameter in the form of Strings as well as a function or list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dataflair_df.groupby(\"Month\").aggregate(['min', max])<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59228\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas.jpg\" alt=\"Apply aggregate function in Pandas\" width=\"1366\" height=\"735\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas-150x81.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas-300x161.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas-768x413.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas-1024x551.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Apply-aggregate-function-in-Pandas-520x280.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>Noticed, the first parameter is in the form of a string and the next parameter is in the form of function.<\/p>\n<p>This has not only grouped the data but implemented more than one function on the data columns.<\/p>\n<h2>Summary<\/h2>\n<p>In this article, we saw how easily we can aggregate and group the data. In addition, we learnt how to apply various functions on pandas dataframes. Hopefully, all your concepts have been cleared with a clear understanding of aggregating and grouping in Pandas.<\/p>\n<p><em><strong>It&#8217;s time to explore<a href=\"https:\/\/data-flair.training\/blogs\/iteration-in-pandas\/\"> 3 unique ways for Pandas iteration<\/a><\/strong><\/em><\/p>\n<p>Leave your queries in the comments section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pandas is popularly known as a data analysis tool, which is offering a data manipulation library. With the help of this feature, we can analyze large data in an efficient manner. Here, we can&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":59253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19475],"tags":[20130,20133,20132,20131],"class_list":["post-59216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pandas","tag-aggregation-in-pandas","tag-pandas-aggregate-dataframes","tag-pandas-group-dataframes","tag-pandas-grouping"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Aggregation and Grouping in Pandas explained by Experts - DataFlair<\/title>\n<meta name=\"description\" content=\"with the helps of Aggregation and Grouping in Pandas we can manipulate data according. Learn how to apply sum, max, min, mean, medium functions with example\" \/>\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\/aggregation-and-grouping-in-pandas\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Aggregation and Grouping in Pandas explained by Experts - DataFlair\" \/>\n<meta property=\"og:description\" content=\"with the helps of Aggregation and Grouping in Pandas we can manipulate data according. Learn how to apply sum, max, min, mean, medium functions with example\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/\" \/>\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=\"2019-06-14T11:34:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-14T11:46:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\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=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Aggregation and Grouping in Pandas explained by Experts - DataFlair","description":"with the helps of Aggregation and Grouping in Pandas we can manipulate data according. Learn how to apply sum, max, min, mean, medium functions with example","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\/aggregation-and-grouping-in-pandas\/","og_locale":"en_US","og_type":"article","og_title":"Aggregation and Grouping in Pandas explained by Experts - DataFlair","og_description":"with the helps of Aggregation and Grouping in Pandas we can manipulate data according. Learn how to apply sum, max, min, mean, medium functions with example","og_url":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-06-14T11:34:13+00:00","article_modified_time":"2019-06-14T11:46:13+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Aggregation and Grouping in Pandas explained by Experts","datePublished":"2019-06-14T11:34:13+00:00","dateModified":"2019-06-14T11:46:13+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/"},"wordCount":667,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg","keywords":["Aggregation in Pandas","Pandas Aggregate dataframes","Pandas Group dataframes","Pandas Grouping"],"articleSection":["Pandas Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/","url":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/","name":"Aggregation and Grouping in Pandas explained by Experts - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg","datePublished":"2019-06-14T11:34:13+00:00","dateModified":"2019-06-14T11:46:13+00:00","description":"with the helps of Aggregation and Grouping in Pandas we can manipulate data according. Learn how to apply sum, max, min, mean, medium functions with example","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/Aggregation-and-Grouping-in-Pandas.jpg","width":802,"height":420,"caption":"Aggregation and Grouping in Pandas"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/aggregation-and-grouping-in-pandas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Pandas Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/pandas\/"},{"@type":"ListItem","position":3,"name":"Aggregation and Grouping in Pandas explained by Experts"}]},{"@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\/59216","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=59216"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/59216\/revisions"}],"predecessor-version":[{"id":59260,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/59216\/revisions\/59260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/59253"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=59216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=59216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=59216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}