0% found this document useful (0 votes)
10 views2 pages

Python Functions and Data Analysis Tasks

The document outlines various programming tasks in Python, including functions for summing numbers, checking even or odd status, and printing integers. It also covers operations with NumPy arrays, creating dataframes with pandas, and performing matrix operations. Additionally, it includes instructions for loading CSV data and visualizing it using matplotlib.
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)
10 views2 pages

Python Functions and Data Analysis Tasks

The document outlines various programming tasks in Python, including functions for summing numbers, checking even or odd status, and printing integers. It also covers operations with NumPy arrays, creating dataframes with pandas, and performing matrix operations. Additionally, it includes instructions for loading CSV data and visualizing it using matplotlib.
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

[Link] a function that takes two arguments and returns their sum.

2 Write a program that checks if a given number is even or odd using if-else
statements.
[Link] a Python loop that prints the first 10 positive integers in ascending
order.
[Link] a NumPy array containing the values [1, 2, 3, 4, 5].
[Link] a 1D NumPy array with 5 random values between 0 and 1.
[Link] two NumPy arrays element-wise.
[Link] = [Link]([[1, 2, 3], [4, 5, 6]])
Returns a tuple representing the dimensions of the array.
[Link] = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Emily'],
'Age': [25, 30, 22, 28, 24],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Miami']
}
Create a dataframe using above data
9.
# Using [Link][] to access rows and columns by labels
alice_data = [Link][0] # Access data for Alice
grades = [Link][:, 'Grade'] # Access 'Grade' column

print(alice_data)

print(grades)

select the rows where the 'Age' column is greater than 25 from the given practice
table1.

10
import pandas as pd

data = {'Date': ['2023-01-15', '2023-03-20', '2023-06-10']}


df = [Link](data)
# Convert the 'Date' column to datetime objects
df['Date'] = pd.to_datetime(df['Date'])

print(df['Date'])
Convert the 'Date' column in the given DataFrame to datetime format .
```python
data = {
'Name': ['Alice', 'Bob', 'Carol'],
'Date': ['2022-03-15', '2021-09-10', '2023-01-25']
}
[Link] are given a CSV file(“sales_data.csv”) containing sales data of a
company with columns: Date, Product, Units Sold, Price per Unit. Write a Python
script to:

● Load the data into a pandas DataFrame.


● Calculate the total sales for each product.
● Plot a bar chart showing the total sales for each product using
matplotlib

12

Matrix Operations

You are given two numpy arrays, A and B, representing matrices. Write a
Python script to:

● Compute the dot product of A and B.

● Calculate the determinant of A.


● Plot a heatmap of matrix B using matplotlib.

You might also like