Omid - Challenge 141

data-challenges
advanced-exercises
🔰 Result ID A B C D E Question
Published

March 24, 2026

Illustration for Omid - Challenge 141

Challenge Description

🔰 Result ID A B C D E Question

Solutions

library(tidyverse)
library(readxl)

path = "files/CH-141 Fill UP and Down.xlsx"
input = read_excel(path, range = "C2:D13")

result = input %>%
  group_by(ID) %>%
  fill(Value, .direction = "downup") 

# As result is not filled with numbers, but highlighted to show which value is proper.
# We need to validate it by eye, but it is correct.
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Aggregates or ranks values at the relevant grouping level

  • Strengths:

    • The R solution stays close to the workbook rule and keeps the transformation compact.
  • Areas for Improvement:

    • The code assumes the sheet structure and source ranges remain stable.
  • Gem:

    • The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd

path = "CH-141 Fill UP and Down.xlsx"
input = pd.read_excel(path, usecols="C:D", skiprows=1, nrows=12)

result = input.groupby('ID', group_keys=False).apply(lambda group: group.ffill().bfill()).reset_index(drop=True)

print(result)

# As result is not filled with numbers, but highlighted to show which value is proper.
# We need to validate it by eye, but it is correct.
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Aggregates or ranks values at the relevant grouping level

  • Strengths:

    • The Python version follows the same rule in a direct dataframe-oriented implementation.
  • Areas for Improvement:

    • The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
  • Gem:

    • The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.

Difficulty Level

This task is moderate:

  • The core logic is clear, but the correct transformation pattern is not obvious from the raw input.

  • The challenge combines multiple reshaping, grouping, or parsing steps.