We start step by step with Groupby
Groupby is a pretty simple concept. We can create a grouping of categories and apply a function to the categories.
Here you can add your file with pd.read_csv() Method
Pandas dataframe.groupby() function is used to split the data into groups based on some criteria. pandas objects can be split on any of their axes. The abstract definition of grouping is to provide a mapping of labels to group names.
Add dataframe.groupby() with pd.read_csv() Method and you can see your DataFrame in type(fortune) & type(sectors)
Operations with Groupby Object
Example of the dataframe.groupby() with len() & nunique() Method
Here you see this 21 grouping by Object and How you can prove this
Example of “Sectors” with size() Method
The size() function is used to get an int representing the number of elements in this object.
Retrieve A Group with the .get_group() Method
Example of the value “Energy” with .get_group() Method
you can see every values in the Sector Column is “Energy”
Methods on the Groupby Object and DataFrame Columns
Example of “Sectors” with max() Method
Pandas max() function returns the maximum of the values in the given object. If the input is a series, the method will return a scalar which will be the maximum of the values in the series. If the input is a dataframe, then the method will return a series with maximum of values over the specified axis in the dataframe. By default the axis is the index axis.
you can see the Sector Column is on the left side
Example of “Sectors” with min() Method
Pandas min() function returns the minimum of the values in the given object. If the input is a series, the method will return a scalar which will be the minimum of the values in the series. If the input is a dataframe, then the method will return a series with minimum of values over the specified axis in the dataframe. By default the axis is the index axis.
Example of “Sectors” with sum() Method
Pandas sum() function is used to return the sum of the values for the requested axis by the user. If the input value is an index axis, then it will add all the values in a column and works same for all the columns. It returns a series that contains the sum of all the values in each column.
Example of “Sectors” with mean () Method
The mean() function is used to return the mean of the values for the requested axis. If we apply this method on a Series object, then it returns a scalar value, which is the mean value of all the observations in the dataframe.
The .agg() Method.
Example of “Sectors” with .agg () Method
Pandas .agg() is used to pass a function or list of function to be applied on a series or even each element of series separately. In case of list of function, multiple results are returned by .agg() method.
Here you can see this “Revenue” “Profits” “Employees” columns with “size” “sum” “mean”
Here you see this “Revenue” column with “size” &”mean”
Iterating through Groups
Example of “fortune.columns” with pd.DataFrame () Method
Here you see the through all of these sections in your Groupby Object
Example of “group” with df.append() Method
You can see that the locations are listed in alphabetical order and for unique location in your DataFrame
About Fellow Consulting
Fellow Consulting AG, based in Poing near Munich, has been advising clients on digitizing their business processes for more than 10 years.
We know how our customers can implement their digital vision. Together with our partners infor_ Amazon AWS, Microsoft Azure, SugarCRM, and Ephesoft, we bring the mission of digitalization to life.
We act as an operational and strategic specialist for our clients as well as a sparring partner for the everyday challenges of digital transformation.