0% found this document useful (0 votes)
10 views21 pages

Python Programming with NumPy & Pandas

The document outlines the learning objectives and key concepts for a Class XII course on Python Programming, focusing on the NumPy and Pandas libraries. It covers data manipulation, including importing/exporting data between CSV files and DataFrames, handling missing values, and implementing linear regression. The document also details the creation and attributes of Pandas data structures, as well as strategies for managing missing data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views21 pages

Python Programming with NumPy & Pandas

The document outlines the learning objectives and key concepts for a Class XII course on Python Programming, focusing on the NumPy and Pandas libraries. It covers data manipulation, including importing/exporting data between CSV files and DataFrames, handling missing values, and implementing linear regression. The document also details the creation and attributes of Pandas data structures, as well as strategies for managing missing data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DAV Centenary Public School

Vaishali Nagar, Jaipur-21


Artificial Intelligence (AI-843)
Class XII
Part-B
(Unit 1: Python Programming-II )
Learning Objectives:

• 1. Review the basics of the NumPy and Pandas


library, including arrays, and essential functions.

• 2. Efficiently import and export data between CSV


files and Pandas Data Frames.

• 3. Implement Linear Regression algorithm,


including data preparation, and model training.
Key Concepts:
1. Recap of NumPy library
2. Recap of Pandas library
3. Importing and Exporting Data between CSV
Files and Data Frames
4. Handling missing values
5. Linear Regression algorithm
Learning Outcomes:
1. Apply the fundamental concepts of the
NumPy and Pandas libraries to perform data
manipulation and analysis tasks.

2. Import and export data between CSV files


and Pandas Data Frames, ensuring data
integrity and consistency.
Python Libraries
• NumPy Library
NumPy, short for Numerical Python is a
powerful library in Python used for numerical
computing. It is a general-purpose array-
processing package.
Pandas Library
• Panel Data : Pandas provides powerful data
manipulation and aggregation functionalities,
making it easy for us to perform complex
analyses and generate insightful visualizations.
This capability is invaluable in AI and data-
driven decision-making processes, allowing
businesses to gain actionable insights from
their data.
Pandas Data Structures
• Pandas generally provides two data structures
for manipulating data, They are:
● Series
● Data Frame
i) Creation of a Series from Scalar Values- A Series can be created
using scalar values as shown below:
ii) Creation of a DataFrame from NumPy arrays
array1=[Link]([90,100,110,120])
array2=[Link]([50,60,70])
array3=[Link]([10,20,30,40]) marksDF =
[Link]([array1, array2, array3],
columns=[ 'A', 'B', 'C', 'D']) print(marksDF)
iii) Creation of a DataFrame from dictionary of array/lists:
• Dealing with Rows and Columns
Deleting Rows or Columns from a DataFrame
Attributes of DataFrames

• [Link]
• [Link]
• [Link]
• [Link](n)
• [Link](n)
Import and Export Data between
CSV Files and DataFrames
• Importing a CSV file to a DataFrame Using the read_csv()
function, we can import tabular data from CSV files into pandas
DataFrame by specifying a parameter value for the file name
(e.g. pd.read_csv("[Link]")). Let us create a DataFrame
from the “[Link]” file. Follow the following steps to
upload the csv file in the google colab file
Exporting a DataFrame to a CSV file We can use the to_csv()
function to save a DataFrame to a text or csv file. For example, to
save the DataFrame df created in above coding

• Program to export this data-


df.to_csv(path_or_buf='C:/PANDAS/[Link]', sep=',')

• This creates a file by the name [Link] in the hard disk.


When we open this file in any text editor or a spreadsheet, we
will find the above data along with the row labels and the
column headers, separated by comma. On Google Colab we
can write the following code
Handling Missing Values

The two most common strategies for handling


missing values explained in this section are:
i) Drop the row having missing values OR
ii) Estimate the missing value
Checking Missing Values
• Pandas provide a function isnull() to check
whether any value is missing or not in the
DataFrame. This function checks all attributes
and returns True in case that attribute has
missing values, otherwise returns False
Drop Missing Values
• Dropping will remove the entire row (object)
having the missing value(s). This strategy
reduces the size of the dataset used in data
analysis, hence should be used in case of
missing values on few objects. The dropna()
function can be used to drop an entire row
from the DataFrame
Estimate the missing value
• Missing values can be filled by using estimations or
approximations e.g a value just before (or after) the
missing value, average/minimum/maximum of the
values of that attribute, etc. In some cases, missing
values are replaced by zeros (or ones). The
fillna(num) function can be used to replace missing
value(s) by the value specified in num. For example,
fillna(0) replaces missing value by 0. Similarly fillna(1)
replaces missing value by 1.
DAV Centenary Public School
Vaishali Nagar, Jaipur-21
Artificial Intelligence (AI-843)
Class XII
Part-B
(Unit 1: Python Programming-II )

You might also like