Javatpoint Logo
Javatpoint Logo

Pandas Pivot table

The Pandas pivot table is used to calculate, aggregate, and summarize your data. It is defined as a powerful tool that aggregates data with calculations such as Sum, Count, Average, Max, and Min.

It also allows the user to sort and filter your data when the pivot table has been created.

Parameters:

  • data: A DataFrame.
  • values: It is an optional parameter and refers the column to aggregate.
  • index: It refers to the column, Grouper, and array.

If we pass an array, it must be of the same length as data.

  • columns: Refers to column, Grouper, and array

If we pass an array, it must be of the same length as data.

  • aggfunc: function, list of functions, dict, default numpy.mean
    If we pass the list of functions, the resulting pivot table will have hierarchical columns whose top level are the function names.
    If we pass a dict, the key is referred to as a column to aggregate, and value is function or list of functions.
  • fill_value[scalar, default None]: It replaces the missing values with a value.
  • margins[boolean, default False]: It add all the row / columns (e.g. for subtotal / grand totals)
  • dropna[boolean, default True] : It drops the columns whose entries are all NaN.
  • margins_name[string, default 'All'] : It refers to the name of the row/column that will contain the totals when margins are True.

Returns:

It returns a DataFrame as the output.

Example:

Output

    P          Q         R
   John       C         24
   Parker     Java      25
   Smith      Python    19
   William    C         22





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA