Question: I have two dataframes as such:

```
df_pos = pd.DataFrame(
    data = [[5,4,3,6,0,7,1,2], [2,5,3,6,4,7,1,0]]
)
df_value = pd.DataFrame(
    data=[np.arange(10 + i, 50 + i, 5) for i in range(0,2)]
)

```

and I want to have a new dataframe `df_final` where df\_pos notates the position and df\_value the corresponding value.

I can do it like this:

```
df_value_copy = df_value.copy()
for i in range(len(df_pos)):
    df_value_copy.iloc[i, df_pos.iloc[i, :]] = df_value.iloc[i].values
df_final = df_value_copy

```

However, I have very large dataframes that would be way too slow. Therefore I want to see whether there is any smarter way to do it.

Answer: 
The easiest way to do this to change the text values themselves to appropriate symbols and use the *ggtext* package for the formatting.

`\u00b0` is the Unicode value for the degree sign. `<sup>3</sup>` is the ggtext Markdown code for superscript 3. You specify that theme text should be markdown by using `ggtext::element_markdown()`.

```r
library(ggplot2)
weatherPLOT = data.frame(weather = rep(c("Soil Temperature (\u00b0C)", 
                                         "Snow Depth (m)", 
                                         "Air Temperature (\u00b0C)", 
                                         "Discharge (m<sup>3</sup>/sec)"), each = 366),
                         day = 1:366,
                         mean = 3, # Obvious place holders,
                         Lo95 = 2, # Are actual numbers in real code
                         Hi95 = 4)

ggplot(aes(y = mean, x = day), data = weatherPLOT) + 
  geom_ribbon(aes(ymin = Lo95, ymax = Hi95), alpha = 0.25) +
  geom_path(size = 1) + 
  labs(y = "", x = "Julian Day") +
  theme(strip.text = ggtext::element_markdown()) +
  facet_wrap( ~ weather, nrow = 2, ncol = 2, scales = "free")

```

![](https://i.imgur.com/8P4dCHE.png)

Created on 2021-08-25 by the [reprex package](https://reprex.tidyverse.org) (v2.0.0)
Another way would be the following:

```
weatherPLOT %>%
  mutate(weather = factor(weather,
                          labels = c(bquote('Air Temperature'*degree*C),
                                     "Discharge~(m^{3}/sec)",
                                     "Snow~Depth~(m)",
                                     bquote('Soil Temperature'*degree*C)))) %>% 
  ggplot(aes(y = mean, x = day)) + 
  geom_ribbon(aes(ymin = Lo95, ymax = Hi95), alpha = 0.25) +
  geom_path(size = 1) + 
  theme(axis.title.y = element_blank()) + xlab("Julian Day") +
  facet_wrap( ~ weather, nrow = 2, ncol = 2, scales = "free", labeller =  label_parsed)

```

[![enter image description here](https://i.stack.imgur.com/LN3ry.png)](https://i.stack.imgur.com/LN3ry.png)