Skip to the content.

Binary Search

lol your kahoot was terrible

%%python
import pandas as pd

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

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


print(find_students_in_range(student_data, 80, 90))
    Name  Score
1    Bob     85
3  David     88
import pandas as pd

def add_letter_grades(df):
    # Define a function to assign letter grades based on score
    def assign_grade(score):
        if score >= 90:
            return 'A'
        elif score >= 80:
            return 'B'
        elif score >= 70:
            return 'C'
        elif score >= 60:
            return 'D'
        else:
            return 'F'

    # Apply the function to the 'Score' column and create the 'Letter' column
    df['Letter'] = df['Score'].apply(assign_grade)
    return df

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

# Test the function
print(add_letter_grades(student_data))
      Name  Score Letter
0    Alice     95      A
1      Bob     85      B
2  Charlie     78      C
3    David     88      B
import pandas as pd

def find_mode(series):
    # Use the .mode() function to find the most common value(s)
    return series.mode()[0]  # Return the first mode in case of multiple modes

# Test the function with a sample Series
print(find_mode(pd.Series([1, 2, 2, 3, 4, 2, 5])))
2