0% found this document useful (0 votes)
1 views4 pages

Class 12 Python Programming Notes

The document provides an overview of Python programming, focusing on its applications in data science, including libraries such as NumPy for numerical operations, Pandas for data handling, and Streamlit for web app development. It explains key concepts like creating and manipulating arrays and data frames, handling CSV files, and managing missing values. Additionally, it highlights important definitions and differences between data structures in Pandas.

Uploaded by

yadavsmriti153
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)
1 views4 pages

Class 12 Python Programming Notes

The document provides an overview of Python programming, focusing on its applications in data science, including libraries such as NumPy for numerical operations, Pandas for data handling, and Streamlit for web app development. It explains key concepts like creating and manipulating arrays and data frames, handling CSV files, and managing missing values. Additionally, it highlights important definitions and differences between data structures in Pandas.

Uploaded by

yadavsmriti153
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

Python Programming

What is Python?

Python is used beyond basic programming. Python is connected with data analysis, file
handling, simple web applications, and beginner-level machine learning. The chapter mainly
covers NumPy, Pandas, CSV file handling, missing values, Streamlit, and linear regression.

Why Python is used in Data Science?

Python is widely used in Artificial Intelligence, Data Science, and Analytics because it is easy
to understand and provides ready-made libraries. Instead of writing long logic from scratch,
we use libraries to perform tasks faster and more efficiently. In this chapter, NumPy helps in
numerical operations, Pandas helps in data handling, and Streamlit helps in web app
development.

What is NumPy Library?

NumPy stands for Numerical Python. It is used for fast mathematical and array-based
operations. In normal Python lists, large calculations may become slow, but NumPy arrays
are optimized for speed.

The main structure of NumPy is ndarray, which stores values in one or more dimensions. A
one-dimensional array stores values in a single row, while a two-dimensional array stores
data in rows and columns like a table.

● Creating Arrays

Arrays can be created using lists, tuples, or nested lists. A 1D array is useful when
storing values in a single line, while a 2D array is useful when data is in matrix or
table form.

● Indexing

Each element in an array has a position called an index. Positive indexing starts from
0, while negative indexing starts from -1 from the last side. This makes it easy to
access both first and last values.

● Updating Values

Using indexing, any value inside the array can be changed. This is useful when
marks, prices, or other numeric values need correction.

● Slicing

Slicing is used when we need only a part of the array. It helps in selecting a range of
values instead of the full array. In 2D arrays, slicing is done separately for rows and
columns, which makes it useful for tables and matrix data.

What is Pandas Library?

Pandas is a powerful library used for handling data in table form. Whenever data comes
from Excel sheets, CSV files, or database tables, Pandas becomes very useful.

The two most important structures in Pandas are Series and DataFrame.

● A Series stores data in a single column form with labels.


● A DataFrame stores data in rows and columns, similar to an Excel sheet. It is the
most useful structure in this chapter because real-world data mostly comes in tabular
form.

● Creating DataFrame

A DataFrame can be created from lists, dictionaries, NumPy arrays, and list of
dictionaries. When a dictionary is used, keys become column names.

● Working with DataFrame

Pandas allows students to add new columns, insert rows, update values, and delete
rows or columns. This makes data modification very easy.

Important Attributes
Some important attributes are frequently used:

● [Link] gives row labels.


● [Link] gives column names.
● [Link] tells the number of rows and columns.
● [Link]() shows the first rows.
● [Link]() shows the last rows.

CSV File Handling

CSV stands for Comma Separated Values. It is one of the most common formats for storing
tabular data. To bring CSV data into Python, we use read_csv(). This converts the file into
a DataFrame. To save processed data back into a CSV file, we use to_csv().

Handling Missing Values

In real datasets, some values may be blank or unavailable. These are called missing values
and are usually shown as NaN. Before analysis, missing values must be handled properly,
otherwise the result may become incorrect.

● The function isnull() is used to identify missing values.


● If rows with missing values are not useful, they can be removed using dropna().
● If the data is important, missing values can be replaced using fillna(). Usually
they are replaced with 0, mean, previous values, or text such as “Unknown”.

Streamlit Library

Streamlit is used to create interactive web applications directly with Python. It is beginner-
friendly because students do not need HTML or CSS for basic apps.

The commonly used functions are [Link](), [Link](), st.text_input(),


st.number_input(), and [Link]().

A simple Streamlit app is first written in [Link], then uploaded to GitHub, and finally
deployed using Streamlit Community Cloud.
Important Definitions

● NumPy is a Python library used for numerical and array operations.


● Series is a one-dimensional labeled structure in Pandas.
● DataFrame is a two-dimensional tabular data structure in Pandas.
● CSV is a file format in which values are separated by commas.
● Missing values are blank or unavailable entries in a dataset.
● Streamlit is a Python library used for making web applications.
● Linear Regression is a machine learning method used for prediction.

Important Differences

A Series stores one-dimensional data, while a DataFrame stores two-dimensional data.

● dropna() removes rows with missing values, while fillna() replaces the missing
values.
● head() shows rows from the top, while tail() shows rows from the bottom.

Quick Revision

● NumPy is used for numerical operations and arrays.


● Pandas is used for data handling and analysis.
● CSV files are imported using read_csv() and exported using to_csv(). Missing
values are checked using isnull(), removed by dropna(), and replaced by
fillna().
● Streamlit is used for web app creation, and linear regression is used for prediction.

You might also like