0% found this document useful (0 votes)
18 views15 pages

Unit 5 Python

NumPy is a powerful library for numerical computing in Python, enabling efficient manipulation of large multi-dimensional arrays and matrices. It supports various operations such as array reshaping, slicing, indexing, and searching, making it essential for data science and machine learning. Additionally, libraries like Pandas, Dask, Matplotlib, and SciPy complement NumPy by providing data analysis, visualization, and scientific computing capabilities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views15 pages

Unit 5 Python

NumPy is a powerful library for numerical computing in Python, enabling efficient manipulation of large multi-dimensional arrays and matrices. It supports various operations such as array reshaping, slicing, indexing, and searching, making it essential for data science and machine learning. Additionally, libraries like Pandas, Dask, Matplotlib, and SciPy complement NumPy by providing data analysis, visualization, and scientific computing capabilities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NumPy (Numerical Python) is a powerful Python library used for numerical computing

and working with arrays and matrices efficiently


A library for handling large,
multi-dimensional arrays Provides fast mathematical operations
Used in Data Science, Machine Learning, AI
Faster than normal Python lists
✔ Uses less memory
✔ Supports vectorized operations (no need for loops)

NumPy
🔹 Array Manipulation
Changing the shape or structure of arrays using functions like reshape.
Helps organize data efficiently for computation.
import numpy as np
a = [Link]([[1,2],[3,4]])
print([Link](4))
Output:
[1 2 3 4]
🔹 Numeric Ranges
Creates arrays with a sequence of numbers using functions like arange().
Useful for generating data automatically.
import numpy as np
print([Link](1,6))
Output:
[1 2 3 4 5]

🔹 Slicing
Extracts a portion of an array using index range.
Helps access specific elements quickly.
import numpy as np
a = [Link]([10,20,30,40])
print(a[1:3])
Output:
[20 30]

🔹 Indexing
Accesses individual elements using position index.
Index starts from 0.
import numpy as np
a = [Link]([5,10,15])
print(a[2])
Output:
15

🔹 Searching
Finds elements matching a condition using functions like where().
Returns index positions.
import numpy as np
a = [Link]([1,2,3,2])
print([Link](a==2))
Output:
(array([1, 3]),)

🔹 Sorting
Arranges elements in ascending order using sort().
Helps organize data.
import numpy as np
a = [Link]([3,1,2])
print([Link](a))
Output:
[1 2 3]

🔹 Splitting
Divides an array into multiple parts using array_split().
Useful for processing chunks of data.
import numpy as np
a = [Link]([1,2,3,4])
print(np.array_split(a,2))
Output:
[array([1, 2]), array([3, 4])]
🔷 Pandas
🔹 Data Analysis
Process of inspecting and organizing data.
Pandas simplifies analysis using tables.
import pandas as pd
df = [Link]({'A':[1,2], 'B':[3,4]})
print(df)
Output:
A B
0 1 3
1 2 4

🔹 DataFrame
A 2D labeled table with rows and columns.
Used to store structured data.
import pandas as pd
df = [Link]({'Name':['A','B'], 'Age':[20,21]})
print(df)
Output:
Name Age
0 A 20
1 B 21
🔹 Data Selection
Selecting specific columns or rows from data.
Done using column names or indexing.
print(df['Name'])
Output:
0 A
1 B
Name: Name, dtype: object

🔹 GroupBy
Groups data based on a column.
Used for aggregation like sum or mean.
import pandas as pd
df = [Link]({'Dept':['IT','IT','CSE'],'Marks':[80,90,85]})
print([Link]('Dept').sum())
Output:
Marks
Dept
CSE 85
IT 170

🔹 Series
A 1D labeled array in Pandas.
Acts like a single column.
import pandas as pd
s = [Link]([10,20,30])
print(s)
Output:
0 10
1 20
2 30
dtype: int64

🔹 Sorting
Arranges data in order using sort_values().
Helps organize datasets.
import pandas as pd
df = [Link]({'Marks':[80,90,70]})
print(df.sort_values('Marks'))
Output:
Marks
2 70
0 80
1 90

🔹 Searching
Finds rows based on conditions.
Uses filtering.
import pandas as pd
df = [Link]({'Marks':[80,90,70]})
print(df[df['Marks']>80])
Output:
Marks
1 90

🔹 Statistics
Performs operations like mean, sum, etc.
Useful for analysis.
import pandas as pd
df = [Link]({'Marks':[80,90,70]})
print(df['Marks'].mean())
Output:
80.0

🔷 Dask
🔹 Dask (Pandas Wrapper)
Used for handling large datasets efficiently.
Works like Pandas but supports parallel computing.
import pandas as pd
import [Link] as dd

pdf = [Link]({'A':[1,2,3]})
df = dd.from_pandas(pdf, npartitions=1)
print([Link]())
Output:
A
0 1
1 2
2 3

🔷 Matplotlib
🔹 Data Visualization
Represents data graphically.
Helps understand patterns easily.
import [Link] as plt
[Link]([1,2,3],[4,5,6])
[Link]()
Line Plot
Displays data using a continuous line.
Used to show trends.
[Link]([1,2,3],[2,4,6])
[Link]()

🔹 Style Properties
Used to customize graph appearance.
Includes color, title, labels.
[Link]([1,2,3],[2,4,6], color='red')
[Link]("Graph")
[Link]()
Multi-line Plot
Displays multiple lines in one graph.
Used for comparison.
[Link]([1,2,3],[2,4,6])
[Link]([1,2,3],[1,3,5])
[Link]()
Scatter Plot
Displays data as points.
Shows relationship between variables.
[Link]([1,2,3],[4,5,6])
[Link]()
🔷 SciPy (Scientific Python)
SciPy is a Python library used for scientific and technical computing.
It provides functions for optimization, integration, statistics, and linear algebra.
Example Program
rom scipy import stats

data = [1,2,3,4,5]
print([Link](data))
DescribeResult(nobs=np.int64(5), minmax=(np.int64(1), np.int64(5)),
mean=np.float64(3.0), variance=np.float64(2.5), skewness=np.float64(0.0),
kurtosis=np.float64(-1.3))

You might also like