library(tidyverse)
library(readxl)
path = "files/CH-182 Indexing Blank cells.xlsx"
input = read_excel(path, range = "B2:D14", col_types = "text")
test = read_excel(path, range = "F2:H14")
result = input %>%
mutate(rn = row_number()) %>%
pivot_longer(cols = -rn, names_to = "col", values_to = "value") %>%
arrange(rn, col) %>%
mutate(value = ifelse(is.na(value), paste0("B", cumsum(is.na(value))), value)) %>%
pivot_wider(names_from = col, values_from = value) %>%
select(-rn)
all.equal(result, test)
#> [1] TRUEOmid - Challenge 182
data-challenges
advanced-exercises
🔰 In the question table, assign an index to the blank cells, starting from 1

Challenge Description
🔰 In the question table, assign an index to the blank cells, starting from 1
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Reshapes the data into the grain required by the task
Builds the intermediate columns that drive the final result
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-182 Indexing Blank cells.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=12, dtype=str)
test = pd.read_excel(path, usecols="F:H", skiprows=1, nrows=12, dtype=str).rename(columns=lambda x: x.split('.')[0])
flat_values = input.values.flatten(order='C')
counter = 1
for i in range(len(flat_values)):
if pd.isna(flat_values[i]):
flat_values[i] = f'B{counter}'
counter += 1
result = pd.DataFrame(flat_values.reshape(input.shape), columns = input.columns)
print(result.equals(test)) # TrueLogic:
Reads the workbook ranges needed for the challenge
Applies the rule iteratively until the output stabilizes
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.