Page 44 - Informatics_Practices_Fliipbook_Class12
P. 44
2 DATA HANDLING USING
PANDAS DATAFRAME
Chapter Outline
2.1 Pandas DataFrame 2.2 Creation of Pandas DataFrame
2.3 Reading from csv File 2.4 Dimensions of a DataFrame
2.5 Summary Information about a DataFrame 2.6 Retrieving Subset of Data - Indexing and Slicing
2.7 Descriptive Statistics 2.8 Data Manipulation
2.9 Writing to csv file 2.10 Grouping and Aggregation
Introduction
In the previous chapter, we learned that a vast amount of data is generated daily from online stores, social media,
e-commerce websites and financial transactions. The data generated on online stores often contains multiple pieces
of information, such as product details (name, quantity, price, purchase time, and payment method). Similarly, social
media generates vast amounts of data about user posts (creator, content, date and time, likes, and comments). A lot
of the above-mentioned data is organized in the form of tables. The DataFrame type (class) available in Pandas makes
it easy to manipulate and analyze the heterogeneous data appearing in the tables.
2.1 Pandas DataFrame
Pandas introduces a data structure called a "DataFrame." Similar to a relational database, a Pandas DataFrame
is a two-dimensional tabular structure that can accommodate objects of various types. It enables us to store and
manipulate tabular data efficiently.
To begin working with DataFrame, we need to import the pandas module. It is customary to use the widely adopted
alias "pd" to refer to the Pandas library, as demonstrated below:
>>> import pandas as pd
>>> type(pd.DataFrame)
output:
type
2.2 Creation of Pandas Dataframe
2.2.1 Creating DataFrame using Dictionary
Suppose, there is a shop that sells gadgets for daily use. It wishes to store and analyze its financial transactions i.e. sales
and expenses. We have expressed five days' data in the form of the dictionary accountsData, using the dictionary
accountsData as the input argument.
30 Touchpad Informatics Practices-XII

