0% found this document useful (0 votes)
20 views6 pages

Practicacl - 1 Aim: Basic Python Programs. (Numpy, Pandas, Matplotlib)

The document provides an overview of three essential Python libraries for data science: NumPy, Pandas, and Matplotlib. NumPy is used for scientific computing and array operations, Pandas for handling labeled and relational data, and Matplotlib for data visualization. Each section includes examples demonstrating the libraries' functionalities and applications.

Uploaded by

butlerkyle428
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)
20 views6 pages

Practicacl - 1 Aim: Basic Python Programs. (Numpy, Pandas, Matplotlib)

The document provides an overview of three essential Python libraries for data science: NumPy, Pandas, and Matplotlib. NumPy is used for scientific computing and array operations, Pandas for handling labeled and relational data, and Matplotlib for data visualization. Each section includes examples demonstrating the libraries' functionalities and applications.

Uploaded by

butlerkyle428
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
You are on page 1/ 6

IU2141230089 DSC(CE0630) 6CSE-B1

PRACTICACL - 1
Aim: Basic Python programs. [ NumPy, Pandas, Matplotlib].
Numpy:
 NumPy (Numerical Python) is a perfect tool for scientific computing and performing
basic and advanced array operations.

 The library offers many handy features performing operations on n-arrays and
matrices in Python. It helps to process arrays that store values of the same data type
and makes performing math operations on arrays (and their vectorization) easier.
In fact, the vectorization of mathematical operations on the NumPy array type
increases performance and accelerates the execution time.

Example:
import numpy as np
array = np.array([1,2,3,4,5,6,7])
print(array)

[1 2 3 4 5 6 7]

array_1 = np.arange(1,100)
print(array_1)

[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
97 98 99]

array_2 = np.mean(array)
print(array_2)

4.0

array_3 = np.random.rand(3,2)
print(array_3)

[[0.35188334 0.98612433]
[0.52235066 0.72803476]
[0.13853962 0.81346437]]

np.random.randint(5, size=(2, 4))

array([[1, 3, 2, 3],
[2, 4, 0, 4]])
IU2141230089 DSC(CE0630) 6CSE-B1

Pandas:
 Pandas is a library created to help developers work with "labeled" and "relational"
data intuitively. It's based on two main data structures: "Series" (one-dimensional,
like a list of items) and "Data Frames" (two-dimensional, like a table with multiple
columns).

 Pandas allows converting data structures to Data Frame objects, handling missing
data, and adding/deleting columns from Data Frame, imputing missing files, and
plotting data with histogram or plot box. It’s a must-have for data wrangling,
manipulation, and visualization.

Example:
import pandas as pd

series = pd.Series([1,2,3,4])
series

0 1
1 2
2 3
3 4
dtype: int64

dataframe =
pd.DataFrame({"Name":["Vinayak","Chirag","Kavan","Harsh","Jenil","Darshil","A
yush"],"Age":[20,20,20,20,20,20,20]})
dataframe

Name Age
0 Vinayak 20
1 Chirag 20
2 Kavan 20
3 Harsh 20
4 Jenil 20
5 Darshil 20
6 Ayush 20

Matplotlib:
 This is a standard data science library that helps to generate data visualizations
such as two-dimensional diagrams and graphs (histograms, scatterplots, non-
Cartesian coordinates graphs). Matplotlib is one of those plotting libraries that are
really useful in data science projects — it provides an object-oriented API for
embedding plots into applications.

 It's thanks to this library that Python can compete with scientific tools like Mat Lab
or Mathematica. However, developers need to write more code than usual while
IU2141230089 DSC(CE0630) 6CSE-B1

using this library for generating advanced visualizations. Note that popular plotting
libraries work seamlessly with Matplotlib.

Example:
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

names = ['group_a', 'group_b', 'dgroup_c']


values = [1, 10, 100]

plt.figure(figsize=(9, 3))

plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting')
plt.show()
IU2141230089 DSC(CE0630) 6CSE-B1

from PIL import Image

img = np.asarray(Image.open('stinkbug.png'))
print(repr(img))

array([[[104, 104, 104],


[104, 104, 104],
[104, 104, 104],
...,
[109, 109, 109],
[109, 109, 109],
[109, 109, 109]],

[[105, 105, 105],


[105, 105, 105],
[105, 105, 105],
...,
[109, 109, 109],
[109, 109, 109],
[109, 109, 109]],

[[107, 107, 107],


[106, 106, 106],
[106, 106, 106],
...,
[110, 110, 110],
[110, 110, 110],
[110, 110, 110]],

...,

[[112, 112, 112],


[111, 111, 111],
[110, 110, 110],
...,
[116, 116, 116],
IU2141230089 DSC(CE0630) 6CSE-B1

[115, 115, 115],


[115, 115, 115]],

[[113, 113, 113],


[113, 113, 113],
[112, 112, 112],
...,
[115, 115, 115],
[114, 114, 114],
[114, 114, 114]],

[[113, 113, 113],


[115, 115, 115],
[115, 115, 115],
...,
[114, 114, 114],
[114, 114, 114],
[113, 113, 113]]], dtype=uint8)

imgplot = plt.imshow(img)

lum_img = img[:, :, 0]
plt.imshow(lum_img)
IU2141230089 DSC(CE0630) 6CSE-B1

<matplotlib.image.AxesImage at 0x7991e8426440>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy