--- jupyter: jupytext: text_representation: extension: .Rmd format_name: rmarkdown format_version: '1.2' jupytext_version: 1.4.1 kernelspec: display_name: Python 3 language: python name: python3 --- ```{python nbsphinx=hidden} import pandas as pd pd.set_option("display.max_rows", 20) ``` ## Spread ```{python} from siuba import _, spread, gather from siuba.data import mtcars ``` ```{python} costs = pd.DataFrame({ 'id': [1,2], 'price_x': [.1, .2], 'price_y': [.4, .5], 'price_z': [.7, .8] }) costs ``` ```{python} long = costs >> gather('measure', 'value', _.price_x, _.price_y, _.price_z) long ``` ```{python} spread(long, "measure", "value") ``` ```{python} one_missing = long[:-1] spread(one_missing, "measure", "value") ``` ```{python} spread(one_missing, "measure", "value", fill = 99) ```