Omid - Challenge 258

data-challenges
advanced-exercises
🔰 Question Result Text {Family:Ezali, age:35} {name:John, age:30, city:Sydney} {name:Omid, website:OmidBI.com} name age
Published

March 24, 2026

Illustration for Omid - Challenge 258

Challenge Description

🔰 Question Result Text {Family:Ezali, age:35} {name:John, age:30, city:Sydney} {name:Omid, website:OmidBI.com} name age

Solutions

library(tidyverse)
library(readxl)
library(jsonlite)

path = "files/200-299/258/CH-258 Column Splitting.xlsx"
input = read_excel(path, range = "B2:B6")
test  = read_excel(path, range = "D2:H6")

result = input %>%
  mutate(across(everything(),
         ~ str_replace_all(.x, "([a-zA-Z0-9\\.]+)", '"\\1"'))) %>%
  mutate(text_parsed = map(Text, ~ fromJSON(.) %>% as_tibble())) %>%
  unnest(text_parsed) %>% 
  select(-Text) 

all.equal(result, test) 
# > [1] TRUE
  • 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
import json

path = "200-299/258/CH-258 Column Splitting.xlsx"
input = pd.read_excel(path, usecols="B", skiprows=1, nrows=5)
test = pd.read_excel(path, usecols="D:H", skiprows=1, nrows=5)

result = (
    pd.DataFrame(
        input['Text']
        .str.replace(r"([a-zA-Z0-9\.]+)", r'"\1"', regex=True)
        .map(json.loads)
        .tolist()
    )
    .assign(age=lambda x: x['age'].astype(float))
)

print(result.equals(test))
  • 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 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.