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

Python Notes Set 6

The document provides an introduction to NumPy and Pandas, covering basic array creation, operations, indexing, and slicing in NumPy, as well as Series and DataFrame creation, access methods, and data operations in Pandas. It includes examples of creating arrays and DataFrames, performing calculations, and manipulating data structures. Key functions and methods for both libraries are highlighted for efficient data handling.

Uploaded by

fake786king
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 views5 pages

Python Notes Set 6

The document provides an introduction to NumPy and Pandas, covering basic array creation, operations, indexing, and slicing in NumPy, as well as Series and DataFrame creation, access methods, and data operations in Pandas. It includes examples of creating arrays and DataFrames, performing calculations, and manipulating data structures. Key functions and methods for both libraries are highlighted for efficient data handling.

Uploaded by

fake786king
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/ 5

Page 1: Introduction to NumPy

import numpy as np

Arrays:

arr = np.array([1, 2, 3])

Zeros and Ones:

np.zeros((2, 3))

np.ones((2, 2))

Basic Operations:

arr + 1, arr * 2, arr.shape, arr.dtype


Page 2: NumPy Indexing and Slicing

Access elements:

arr[0], arr[-1]

Slicing:

arr[1:3], arr[:], arr[::-1]

Boolean Indexing:

arr[arr > 2]

Multidimensional Access:

arr[1, 2], arr[:, 1]


Page 3: NumPy Functions

Useful functions:

np.mean(arr), np.std(arr), np.sum(arr)

np.max(arr), np.min(arr), np.argmax(arr)

Reshape and Flatten:

arr.reshape(3, 2), arr.flatten()


Page 4: Introduction to Pandas

import pandas as pd

Series:

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

DataFrame:

df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})

Access:

df['A'], df.loc[0], df.iloc[0]


Page 5: Pandas Data Operations

df.head(), df.tail()

df.describe(), df.info()

Filtering:

df[df['A'] > 1]

Adding Columns:

df['C'] = df['A'] + df['B']

Drop Columns:

df.drop('C', axis=1)

You might also like