About Lesson
Implement a Program Using the math Library
- Objective: Write a Python program that uses the
math
library to perform various mathematical operations. - Steps:
- Import the
math
library. - Perform operations like calculating the square root, power, and trigonometric functions.
python
import math number = 16 print(f"Square root of {number} is {math.sqrt(number)}") print(f"2 raised to the power 3 is {math.pow(2, 3)}") print(f"Sine of 90 degrees is {math.sin(math.radians(90))}")
- Import the
Write a Data Analysis Script Using Pandas
- Objective: Write a Python script that uses the
Pandas
library to perform data analysis on a dataset. - Steps:
- Import the
pandas
library. - Create a
DataFrame
from a dictionary or read from a CSV file. - Perform basic data analysis operations like calculating mean, sum, and filtering data.
python
import pandas as pd # Creating a DataFrame from a dictionary data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Salary': [50000, 60000, 70000]} df = pd.DataFrame(data) # Display the DataFrame print(df) # Calculate the mean age print(f"Mean age: {df['Age'].mean()}") # Filter data where Salary is greater than 55000 high_salary = df[df['Salary'] > 55000] print("Employees with salary greater than 55000:") print(high_salary)
- Import the