library(tidyverse)
library(readxl)
path <- "300-399/328/CH-328 Text Cleaning.xlsx"
input <- read_excel(path, range = "B2:B9")
test <- read_excel(path, range = "D2:D9")
result = input %>%
mutate(Level = Level %>%
str_replace_all("Ground", "Ground,") %>%
str_replace_all(",$", "") %>%
str_split(", ") %>%
map_chr(~ paste(unique(.x), collapse = ", ")))Omid - Challenge 328

Challenge Description
🔰 The Level column in the question table is created by grouping rows with the same ID, which results in some repeated text values.
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Builds the intermediate columns that drive the final result
Parses the text patterns directly instead of relying on manual cleanup
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 = "300-399\\328\\CH-328 Text Cleaning.xlsx"
input = pd.read_excel(path, usecols="B", nrows = 8, skiprows = 1)
test = pd.read_excel(path, usecols="D", nrows = 8, skiprows = 1); test.columns = [col.replace('.1', '') for col in test.columns]
result = (
input.assign(
Level=(
input["Level"]
.str.replace("Ground", "Ground,", regex=False)
.str.replace(",$", "", regex=True)
.str.split(", ")
.map(lambda x: ", ".join(pd.unique(pd.Series(x))))
)
)
)
print(result.equals(test))
# TrueLogic:
Reads the workbook ranges needed for the challenge
Builds the intermediate columns that drive the final result
Parses the text patterns directly instead of relying on manual cleanup
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.