library(tidyverse)
library(readxl)
library(charcuterie)
path = "files/CH-136 Column Splitting.xlsx"
input = read_excel(path, range = "B2:B8")
test = read_excel(path, range = "D2:F8", col_types = "text")
separate_by_double = function(string) {
chars = chars(string)
for (i in 1:(length(chars) - 1)) {
if (chars[i] == chars[i + 1]) {
chars[i] = paste0(chars[i], ",")
}
}
df = data.frame(chars = string(chars)) %>% separate(chars, into = c("ID.1","ID.2","ID.3"), sep = ",")
print(df)
}
result = map_dfr(input$ID, separate_by_double)
all.equal(result, test, check.attributes = FALSE)
# 21 in test has dot and decimal zero.Omid - Challenge 136
data-challenges
advanced-exercises
🔰 Challenge 136: Column Splitting!

Challenge Description
🔰 Challenge 136: Column Splitting!
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Applies the rule iteratively until the output stabilizes
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
from itertools import groupby
# Read the Excel file
path = "CH-136 Column Splitting.xlsx"
input = pd.read_excel(path, usecols="B", skiprows=1, nrows=7)
test = pd.read_excel(path, usecols="D:F", skiprows=1, nrows=7, dtype=str).fillna("")
def separate_by_double(string):
split_data = [string[0]]
for i in range(1, len(string)):
if string[i] == string[i - 1]:
split_data[-1] += ","
split_data.append(string[i])
split_data = ''.join(split_data).split(",")
return split_data + [""] * (3 - len(split_data))
result = pd.DataFrame([separate_by_double(id) for id in input.iloc[:, 0]], columns=["ID.1", "ID.2", "ID.3"])
print(result.equals(test)) # Output: TrueLogic:
Reads the workbook ranges needed for the challenge
Aggregates or ranks values at the relevant grouping level
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 business rule is readable, but the workbook still requires careful implementation to reach the expected layout.