Skip to the content.

List and Filtering homework

Popcorn Hack #1 import pandas as pd

Sample student_data for testing

student_data = pd.DataFrame({ ‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’, ‘David’], ‘Score’: [85, 92, 78, 88] })

Function to find students with scores in a specific range

def find_students_in_range(df, min_score, max_score): return df[(df[‘Score’] >= min_score) & (df[‘Score’] <= max_score)]

Test the function

print(find_students_in_range(student_data, 80, 90))

Name  Score 0  Alice     85 3  David     88 Popcorn Hack #2 import pandas as pd

Sample student_data

student_data = pd.DataFrame({ ‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’, ‘David’, ‘Eve’], ‘Score’: [85, 92, 78, 64, 55] })

Function to add a ‘Letter’ column

def add_letter_grades(df): def get_letter(score): if score >= 90: return ‘A’ elif score >= 80: return ‘B’ elif score >= 70: return ‘C’ elif score >= 60: return ‘D’ else: return ‘F’

df['Letter'] = df['Score'].apply(get_letter)
return df

Test it

print(add_letter_grades(student_data))

  Name  Score Letter 0    Alice     85      B 1      Bob     92      A 2  Charlie     78      C 3    David     64      D 4      Eve     55      F Pocorn Hack #3 import pandas as pd

Function to find the mode (most common value) in a Series

def find_mode(series): return series.mode().iloc[0] # returns the first mode if multiple exist

Test it

print(find_mode(pd.Series([1, 2, 2, 3, 4, 2, 5])))

2 Homework Hack import pandas as pd

Load your dataset

datas = pd.read_csv(‘data_title.csv’) # Replace with your actual filename datas.head()

SQL Series – Average temperature and wind speed per vegetation type SELECT vegetation_type, AVG(temperature), AVG(wind_speed) FROM fire_incidents GROUP BY vegetation_type;

– High temperature and wind speed events SELECT * FROM fire_incidents WHERE temperature > 120 AND wind_speed > 15;

– Avg fire intensity per weather condition SELECT weather_condition, AVG(fire_intensity) FROM fire_incidents GROUP BY weather_condition;