question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reshape table using Pivot

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zyzhucommented, Jan 14, 2021

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

0reactions
ashleydaviscommented, Jan 15, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found