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

NumPy, Pandas, Matplotlib Guide

The document provides an overview of key Python libraries including NumPy for numerical computing, Pandas for data analysis, and Matplotlib for plotting. It details their features, key functions, and examples of usage. Additionally, it discusses Python IDEs, highlighting popular options and their functionalities.

Uploaded by

tiwarinitish960
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)
4 views6 pages

NumPy, Pandas, Matplotlib Guide

The document provides an overview of key Python libraries including NumPy for numerical computing, Pandas for data analysis, and Matplotlib for plotting. It details their features, key functions, and examples of usage. Additionally, it discusses Python IDEs, highlighting popular options and their functionalities.

Uploaded by

tiwarinitish960
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

UNIT-5

1. NumPy (Numerical Python)


Introduction:
NumPy is a powerful Python library used for numerical computing. It provides support for
arrays, matrices, and a large number of mathematical functions to operate on these data
structures. It is the foundation for most scientific computing libraries in Python.

Features:
• N-dimensional arrays (ndarray)
• Broadcasting functions
• Vectorized operations
• Linear algebra, FFT, and random number capabilities

Key Functions and Examples:


1.1 Array Creation
import numpy as np

# 1D array
a = [Link]([1, 2, 3])
# 2D array
b = [Link]([[1, 2], [3, 4]])
# Zeros, Ones, Full
[Link]((2, 3)), [Link]((3, 2)), [Link]((2, 2), 7)
# Range and Linspace
[Link](0, 10, 2), [Link](0, 1, 5)

1.2 Array Attributes


[Link], [Link], [Link], [Link], [Link], [Link]

1.3 Reshape and Flatten


[Link](4, 1), [Link](), [Link]()

1.4 Indexing and Slicing


a[1], b[0, 1], b[:, 1], b[1, :], b[::, ::-1]

1.5 Mathematical Functions


[Link](a), [Link](a), [Link](a), [Link](a), [Link](a), [Link](a),
[Link](a), [Link](a), [Link](a)
1.c Matrix Multiplication and Linear Algebra
[Link](b, b.T), [Link](b, b.T), [Link]([Link]([[1., 2.], [3.,
4.]]))
[Link]([Link]([[1., 2.], [3., 4.]])), [Link](b),
[Link](b)

1.7 Random Module


[Link](2, 2), [Link](1, 10, size=(2, 2)),
[Link](0, 1, size=(2, 2))
[Link]([10, 20, 30], size=5)

1.8 Sorting and Searching


[Link](a), [Link](a > 1), [Link](a), [Link](a), [Link]([1,2,2,3])

1.S More Useful Functions


[Link](a, [4, 5]), [Link](a, 1, 10), [Link](a, 0), [Link](a, 1, 2)

2. Pandas
Introduction:
Pandas is an open-source library providing high-performance, easy-to-use data structures
and data analysis tools. It is built on top of NumPy.

Features:
• DataFrame and Series objects
• Handling missing data
• Grouping and aggregating
• Reading/writing to files (CSV, Excel, etc.)

Key Functions and Examples:


2.1 Creating Series and DataFrames
import pandas as pd

s = [Link]([1, 2, 3])
df = [Link]({"A": [1, 2], "B": [3, 4]})
[Link]([Link](3, 3), columns=['X', 'Y', 'Z'])

2.2 Reading and Writing Files


df = pd.read_csv('[Link]')
df.to_csv('[Link]', index=False)
df.to_excel('[Link]')
pd.read_excel('[Link]')
2.3 Data Selection
df['A'], [Link][0], [Link][1, 1], [Link][0, 'A'], [Link][1, 1]

2.4 Filtering and Boolean Indexing


df[df['A'] > 1], df[(df['A'] > 1) & (df['B'] < 4)]

2.5 Missing Values


[Link](), [Link](), [Link](0), [Link](method='ffill')

2.c Aggregation and Grouping


[Link]('A').sum(), [Link]('A').mean(), [Link](['sum', 'mean'])

2.7 Merging, Joining, Concatenating


[Link](df1, df2, on='id')
[Link](df2, lsuffix='_left', rsuffix='_right')
[Link]([df1, df2])

2.8 Sorting and Ranking


df.sort_values('A'), df.sort_index(), [Link]()

2.S Date and Time Functions


dates = pd.date_range('20230101', periods=6)
df['date'] = dates
df['year'] = df['date'].[Link]
df['month'] = df['date'].[Link]

2.10 Useful Utilities


[Link](), [Link](), df.value_counts(), [Link]()

3. Matplotlib
Introduction:
Matplotlib is a 2D plotting library for Python. It is used to generate plots, histograms, bar
charts, scatterplots, etc.

Features:
• Easy-to-use interface for creating plots
• Customizable plot elements
• Support for subplots

Key Functions and Examples:


3.1 Basic Plotting
import [Link] as plt
x = [1, 2, 3]
y = [2, 4, 6]
[Link](x, y)
[Link]("Line Plot")
[Link]("X-axis")
[Link]("Y-axis")
[Link](True)
[Link]()

3.2 Bar, Scatter, Histogram


[Link](x, y)
[Link](x, y)
[Link]([1,2,1,2,3,4,4,4], bins=4)

3.3 Subplots and Customization


fig, axs = [Link](2)
axs[0].plot(x, y)
axs[1].bar(x, y)
axs[0].set_title('Line')
axs[1].set_title('Bar')

3.4 Save Figure


[Link]('[Link]')

3.5 Styling and Legends


[Link](x, y, label='Line')
[Link]()
[Link]('ggplot')

4. Login Form Using Tkinter


import tkinter as tk
from tkinter import messagebox

def login():
username = entry_user.get()
password = entry_pass.get()
if username == "admin" and password == "admin123":
[Link]("Login", "Login Successful")
else:
[Link]("Login", "Invalid Credentials")

app = [Link]()
[Link]("Login Form")
[Link]("300x200")

label_user = [Link](app, text="Username")


label_user.pack()
entry_user = [Link](app)
entry_user.pack()

label_pass = [Link](app, text="Password")


label_pass.pack()
entry_pass = [Link](app, show="*")
entry_pass.pack()

btn_login = [Link](app, text="Login", command=login)


btn_login.pack()

[Link]()

5. Python IDEs (Integrated Development Environments)


Introduction:
An IDE is a software application that provides comprehensive facilities to programmers for
software development. Python IDEs simplify writing code by integrating features such as
syntax highlighting, code completion, debugging tools, and more.

Popular Python IDEs:


1. IDLE (Integrated Development and Learning Environment)
• Comes pre-installed with Python.
• Lightweight and simple for beginners.
• Interactive shell and basic editor.
2. PyCharm
• Developed by JetBrains.
• Community (free) and Professional (paid) versions.
• Advanced features like intelligent code completion, refactoring, and debugging.
3. VS Code (Visual Studio Code)
• Developed by Microsoft.
• Lightweight and customizable with extensions.
• Supports Python debugging, linting, and Jupyter Notebooks.
4. Jupyter Notebook
• Best for data science and machine learning.
• Allows code, equations, visualizations, and narrative text in a single document.
5. Spyder
• Specifically designed for scientific computing.
• Features like variable explorer, interactive console, and integration with NumPy,
Pandas, and Matplotlib.
c. Thonny
• Ideal for beginners.
• Simple UI with a debugger and variable viewer.
7. Anaconda Navigator
• A GUI that manages environments and launches IDEs like JupyterLab, Spyder, etc.
• Preferred for data science projects.

You might also like