library(tidyverse)
library(readxl)
input = read_excel("files/CH-039 Transformation.xlsx", range = 'B2:E10', col_names = F)
test = read_excel("files/CH-039 Transformation.xlsx", range = 'G1:G22')
result = input %>%
pivot_longer(everything(), names_to = NULL) %>%
arrange(value) %>%
na.omit() %>%
distinct()
identical(result$value, test$`Result - Unique Code`)
# [1] TRUEOmid - Challenge 39
data-challenges
advanced-exercises
🔰 : Transformation!

Challenge Description
🔰 : Transformation!
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Reshapes the data into the grain required by the task
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
input = pd.read_excel("CH-039 Transformation.xlsx", sheet_name="Sheet1", usecols="B:E", nrows=9)
test = pd.read_excel("CH-039 Transformation.xlsx", sheet_name="Sheet1", usecols="G", nrows=22)
input = input.stack().reset_index(drop=True)
input = input.sort_values().drop_duplicates().reset_index(drop=True)
input = pd.DataFrame(input, columns=['result'])
print(input['result'].equals(test['Result - Unique Code'])) # TrueLogic:
- Reads the workbook ranges needed for the challenge
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.