Reshape table using Pivot
See original GitHub issueHello 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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Reshaping and pivot tables — pandas 1.5.2 documentation
To reshape the data into this form, we use the DataFrame.pivot() method ... The function pivot_table() can be used to create spreadsheet-style pivot...
Read more >Reshaping in Pandas - Pivot, Pivot-Table, Stack and Unstack
In Pandas data reshaping means the transformation of the structure of a table or vector (i.e. DataFrame or Series) to make it suitable...
Read more >pandas - How to reshape a Pivot Table? - Stack Overflow
Try: brincando3 = df4.pivot_table('OCCUPANCY %', 'NAME', 'NEW_TIME', aggfunc='median') \ .rename_axis(columns=None). Don't use ['OCCUPANCY ...
Read more >Reshaping & Pivot Tables in Pandas
Pivot table in Pandas is an tool to summarize one or more numeric variable based on two other categorical variables. To show how...
Read more >4 Pandas Function to Reshape Table Layout
Now we have our table sorted by the size column first then continued by the tip column in a descending way. 2.pivot. Pivot...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!