library(tidyverse)
library(readxl)
path = "Excel/800-899/800/800 Split and Expand.xlsx"
input = read_excel(path, range = "A2:B6")
test = read_excel(path, range = "D2:E12")
result = input %>%
separate_rows(Band, sep = ", ") %>%
filter(str_detect(Band, "-")) %>%
mutate(Band = str_split(Band, "-")) %>%
mutate(Numbers = map(Band, ~seq(from = as.numeric(.x[1]), to = as.numeric(.x[2])))) %>%
unnest(Numbers) %>%
select(-Band)
all.equal(result, test, check.atrributes= T)
# TRUEExcel BI - Excel Challenge 800
excel-challenges
excel-formulas
🔰 Generate the given output by splitting the ranges given.

Challenge Description
🔰 Generate the given output by splitting the ranges given. If range is not there, then skip that number.
Solutions
- Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Parse the packed text or string structure.
- Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd
path = "800-899/800/800 Split and Expand.xlsx"
input = pd.read_excel(path, usecols="A:B", skiprows=1, nrows=4)
test = pd.read_excel(path, usecols="D:E", skiprows=1, nrows=11).rename(columns=lambda c: c.replace('.1', ''))
input_expanded = input.assign(
Band=input['Band'].str.split(', ')
).explode('Band')
input_expanded = input_expanded[input_expanded['Band'].str.contains('-')]
input_expanded['Numbers'] = input_expanded['Band'].str.split('-').apply(lambda x: range(int(x[0]), int(x[1]) + 1))
result = input_expanded.explode('Numbers').drop(columns='Band').reset_index(drop=True)
result['Numbers'] = result['Numbers'].astype(int)
print(result.equals(test)) # TrueThe Python version mirrors the same workbook logic with a concise, direct implementation.
Difficulty Level
Easy / Medium
The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.