TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas Pivot Table

Pandas Pivot Table with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Pandas DataFrame.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:

# importing pandas as pd 
import pandas as pd 
import numpy as np 
   
# create dataframe 
info = pd.DataFrame({'P': ['Smith', 'John', 'William', 'Parker'], 
      'Q': ['Python', 'C', 'C++', 'Java'], 
      'R': [19, 24, 22, 25]}) 
info 
table = pd.pivot_table(info, index =['P', 'Q'])   
table

Output

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

Next TopicDataFrame.query()




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf