Reshape table using Pivot
Hello I'm trying to reshape a table like the following example from: pydata Pandas Reshaping
So far I have tried with the following code:
df = new dataForge.DataFrame({columns: {"foo": ["one", "one", "one", "two", "two","two"],
"bar": ["a", "b", "c", "a", "b", "c"],
"baz": [1, 2, 3, 4, 5, 6]}})
df = df.setIndex("foo").dropSeries("foo").bake()
df.pivot("bar", "baz", dataForge.Series.sum).toString()
which yields
__index__ bar baz
--------- --- ---
0 a 5
1 b 7
2 c 9
But it seems to just ignore the index and group by the "baz" column. I have tried different variations but still I cant get it to work.
How can I achieve what is shown on the picture above?
Have you read the guide for the pivot function?
https://github.com/data-forge/data-forge-ts/blob/master/docs/guide.md#pivot
Try reading that first and you might find what you are looking for.
Otherwise I'll come back and have a look next week.
Thanks for the suggestion, I have read the guide for the pivot function. What I'm trying to achieve is to group a column and then use that column as the header row while reshaping the dataframe. If we go back to the example on the image it is using the "foo" column as an index and then grouping and using the "bar" column as the new header on the output. The following is the result I'm trying to get:
__index__ a b c
--------- --- --- ---
one 1 2 3
two 4 5 6
I'm sorry after reading the documentation for Pandas pivot and pivot_table I think that the Data-Forge pivot function works like pivot_table rather than pivot.
What do you ultimately hope to do with this? If you could explain the problem you are trying to solve I can probably find another way to help you achieve it.
I am exploring the same problem today using data-forge. I think this chapter explains well the similar scenarios and rationales of pivot in R's tidyverse https://r4ds.had.co.nz/tidy-data.html
Thanks for the info. I'm hoping to spend more time this year expanding Data-Forge, so stay tuned.
Although if you'd like to contribute to improving this code library, please do!
Sorry, never got back to this issue.
If anyone else is able to contribute a PR for this I'll be open to reopen this issue.