scrapbook icon indicating copy to clipboard operation
scrapbook copied to clipboard

Operations on scraps

Open a-baughman opened this issue 6 years ago • 1 comments

Hello, I'm using Papermill to create a a directory with output notebooks. In those notebooks I have used sb.glue("Word Count", df_sum, "display") to glue a data frame then using sb.reglue in another. So, in this summary notebook I have the reglue("Word Count") for each of the files in the directory, which then displays ~70 of the same data frames run on different data using Papermill. I would like to take a sum of the values of a certain row across all of the data frames in this summary notebook that uses reglue. Is there a way that you suggest I go about doing this? I am having trouble because when I reglue I am unsure of how I can actually "touch" the data in the reglued data frame to do an operation across many, such as the sum. Thanks in advance!

a-baughman avatar Apr 03 '19 23:04 a-baughman

You can actually access the data that's reglue'd directly via scraps on an individual notebook and notebook_scraps/scraps on a collection of notebooks. Thus depending on how your glue'd data is setup you can iterate on over the scraps and extract the values you wish to sum.

For example to read the first row of each dataframe glued to the same name (glue_df_json in this case) it might look something like this:

sum(df_json[0]["result_column"] for scraps in books.notebook_scraps.values() for df_json in scraps["glue_df_json"])

MSeal avatar Apr 04 '19 03:04 MSeal