library(tidyverse)
library(readxl)
path = "files/200-299/279/CH-279 Transforming.xlsx"
input = read_excel(path, range = "B2:C8")
test = read_excel(path, range = "G2:H13")
result = input %>%
mutate(prev = lag(Price)) %>%
pivot_longer(c(prev, Price), values_to = "Price", values_drop_na = TRUE) %>%
select(-name)
ggplot(result, aes(Date, Price)) +
geom_step() +
geom_point()
ggsave("files/200-299/279/CH-279 Transforming R.png", width = 6, height = 4)
all.equal(result, test, check.attributes = FALSE)
# > [1] TRUEOmid - Challenge 279
data-challenges
advanced-exercises
🔰 Group Challenge 279: Step Chart Transformation!

Challenge Description
🔰 Group Challenge 279: Step Chart Transformation!
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
import matplotlib.pyplot as plt
path = "200-299/279/CH-279 Transforming.xlsx"
input = pd.read_excel(path, usecols="B:C", skiprows=1, nrows=6)
test = pd.read_excel(path, usecols="G:H", skiprows=1, nrows=12)
input["prev"] = input["Price"].shift()
result = pd.melt(
input, id_vars="Date", value_vars=["prev", "Price"], value_name="Price_val"
).dropna()[["Date", "Price_val"]].rename(columns={"Price_val": "Price"})
result = result.sort_values("Date").reset_index(drop=True)
print(result)
plt.plot(result["Date"], result["Price"], marker='o')
plt.xlabel("Date")
plt.ylabel("Price")
plt.title("Line Plot of Price Over Date")
plt.show()Logic:
Reads the workbook ranges needed for the challenge
Reshapes the data into the grain required by the task
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.