0% found this document useful (0 votes)
52 views3 pages

Learning NumPy and Pandas

Uploaded by

piyushshah16op
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)
52 views3 pages

Learning NumPy and Pandas

Uploaded by

piyushshah16op
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

Learning NumPy and pandas

1. NumPy (Numerical Python)

Purpose: Work with numerical data using arrays (faster and more efficient than Python lists).

Installation: Run `pip install numpy`.

Key Concepts:

1. Creating Arrays:

import numpy as np

# 1D array

arr1 = [Link]([1, 2, 3])

# 2D array

arr2 = [Link]([[1, 2], [3, 4]])

2. Basic Operations:

arr = [Link]([1, 2, 3])

print(arr + 1) # [2, 3, 4] (element-wise addition)

print(arr * 2) # [2, 4, 6] (element-wise multiplication)

3. Useful Functions:

[Link]((2, 3)) # 2x3 array of zeros

[Link]((3, 3)) # 3x3 array of ones

[Link](arr) # Sum of elements

[Link](arr) # Average

2. pandas (Panel Data)


Learning NumPy and pandas

Purpose: Work with structured data (tables).

Installation: Run `pip install pandas`.

Key Concepts:

1. Main Data Structures:

- Series: One-dimensional data (like a list with labels).

- DataFrame: Two-dimensional data (like a table).

2. Creating a DataFrame:

import pandas as pd

data = {"Name": ["Alice", "Bob"], "Age": [25, 30]}

df = [Link](data)

print(df)

3. Reading and Writing Files:

df = pd.read_csv("[Link]") # Read a CSV file

df.to_csv("[Link]", index=False) # Save to CSV

4. Basic Operations:

print(df["Name"]) # Access a column

print([Link][0]) # Access a row by position

print(df[df["Age"] > 25]) # Filter rows

5. Common Functions:
Learning NumPy and pandas

[Link]() # Summary of numerical data

[Link]() # Info about columns and data types

df.sort_values("Age") # Sort by a column

[Link]("Age", axis=1) # Drop a column

You might also like