Consider the data of healthcare drugs as provided in the excel sheet. The concept of pivot tables in python allows you to extract the significance from a large detailed dataset. A pivot table helps in tracking only the required information from the data frames. It summarizes the data. The panda’s pivot table is a good alternative instead of using other tools for analysing the data. The following are the features for using panda’s pivot table.

  • It is quicker.
  • It is self-documenting
  • It is easy to use for generating a report or email
  • It is more flexible in defining the aggregation functions.

Consider this below dataset for execution. Download the dataset which is available here. In this article, you will learn python pivots with many examples.

Data set of Health Care Drugs

The pivot table must have a data frame and an index. Run the below code which has used “Patient Name” as an index.

Example 1:

import pandas as pd

import numpy as np
df = pd.read_excel(“C:\\Users\\admin\\Desktop\\drugs.xlsx”)
data = pd.pivot_table(df,index=[“Patient Name”])
print(data)

#python-pandas #data-extraction #pivot-tables #python-numpy #data-science

Data Extraction with Pivot Tables
5.80 GEEK