displaying data in Jupyter pivottable.js
I have a pandas DataFrame with 3 columns : product, region, and cost.
I want to display a pivot table using pivottable.js in a Jupyter notebook such that product are rows, region are columns and cost are values.
I have tried :
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({'region':['N', 'S', 'W', 'E', 'N', 'S', 'W', 'E'],
'product':['P1', 'P1', 'P1', 'P1', 'P2', 'P2', 'P2', 'P2'],
'cost':[10, 13, 17, 28, 29, 23, 17, 18]})
pivot_ui(df, rows=['product'], cols=['region'], values=['cost'])
But this does not work, since there does not exist a values attribute for pivot_ui().
How to do that ?
python jupyter pivottable.js
add a comment |
I have a pandas DataFrame with 3 columns : product, region, and cost.
I want to display a pivot table using pivottable.js in a Jupyter notebook such that product are rows, region are columns and cost are values.
I have tried :
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({'region':['N', 'S', 'W', 'E', 'N', 'S', 'W', 'E'],
'product':['P1', 'P1', 'P1', 'P1', 'P2', 'P2', 'P2', 'P2'],
'cost':[10, 13, 17, 28, 29, 23, 17, 18]})
pivot_ui(df, rows=['product'], cols=['region'], values=['cost'])
But this does not work, since there does not exist a values attribute for pivot_ui().
How to do that ?
python jupyter pivottable.js
add a comment |
I have a pandas DataFrame with 3 columns : product, region, and cost.
I want to display a pivot table using pivottable.js in a Jupyter notebook such that product are rows, region are columns and cost are values.
I have tried :
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({'region':['N', 'S', 'W', 'E', 'N', 'S', 'W', 'E'],
'product':['P1', 'P1', 'P1', 'P1', 'P2', 'P2', 'P2', 'P2'],
'cost':[10, 13, 17, 28, 29, 23, 17, 18]})
pivot_ui(df, rows=['product'], cols=['region'], values=['cost'])
But this does not work, since there does not exist a values attribute for pivot_ui().
How to do that ?
python jupyter pivottable.js
I have a pandas DataFrame with 3 columns : product, region, and cost.
I want to display a pivot table using pivottable.js in a Jupyter notebook such that product are rows, region are columns and cost are values.
I have tried :
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({'region':['N', 'S', 'W', 'E', 'N', 'S', 'W', 'E'],
'product':['P1', 'P1', 'P1', 'P1', 'P2', 'P2', 'P2', 'P2'],
'cost':[10, 13, 17, 28, 29, 23, 17, 18]})
pivot_ui(df, rows=['product'], cols=['region'], values=['cost'])
But this does not work, since there does not exist a values attribute for pivot_ui().
How to do that ?
python jupyter pivottable.js
python jupyter pivottable.js
asked Nov 25 '18 at 22:09
M. PageM. Page
1,9321921
1,9321921
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The first problem is that this function doesn't accept a values kwarg, but rather vals.
The second issue you'll face is that you'll need to specify an aggregation function (the default is Count) to summarize your values. This is sort of similar to the pandas pivot table's aggfunc argument. If you expect to only have a single value then something like pivot_ui(df, rows=['product'], cols=['region'], vals=['cost'], aggregatorName='First') should do the trick.
By way of explanation, your code above is just providing the Count of input records per cell. Count doesn't accept any arguments, so passing in vals on its own won't change that. First does accept arguments, so passing in vals=['cost'] will cause each cell to contain the first value of cost (ordered via "natural sort") per cell.
works perfectly !
– M. Page
Nov 26 '18 at 7:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472501%2fdisplaying-data-in-jupyter-pivottable-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The first problem is that this function doesn't accept a values kwarg, but rather vals.
The second issue you'll face is that you'll need to specify an aggregation function (the default is Count) to summarize your values. This is sort of similar to the pandas pivot table's aggfunc argument. If you expect to only have a single value then something like pivot_ui(df, rows=['product'], cols=['region'], vals=['cost'], aggregatorName='First') should do the trick.
By way of explanation, your code above is just providing the Count of input records per cell. Count doesn't accept any arguments, so passing in vals on its own won't change that. First does accept arguments, so passing in vals=['cost'] will cause each cell to contain the first value of cost (ordered via "natural sort") per cell.
works perfectly !
– M. Page
Nov 26 '18 at 7:01
add a comment |
The first problem is that this function doesn't accept a values kwarg, but rather vals.
The second issue you'll face is that you'll need to specify an aggregation function (the default is Count) to summarize your values. This is sort of similar to the pandas pivot table's aggfunc argument. If you expect to only have a single value then something like pivot_ui(df, rows=['product'], cols=['region'], vals=['cost'], aggregatorName='First') should do the trick.
By way of explanation, your code above is just providing the Count of input records per cell. Count doesn't accept any arguments, so passing in vals on its own won't change that. First does accept arguments, so passing in vals=['cost'] will cause each cell to contain the first value of cost (ordered via "natural sort") per cell.
works perfectly !
– M. Page
Nov 26 '18 at 7:01
add a comment |
The first problem is that this function doesn't accept a values kwarg, but rather vals.
The second issue you'll face is that you'll need to specify an aggregation function (the default is Count) to summarize your values. This is sort of similar to the pandas pivot table's aggfunc argument. If you expect to only have a single value then something like pivot_ui(df, rows=['product'], cols=['region'], vals=['cost'], aggregatorName='First') should do the trick.
By way of explanation, your code above is just providing the Count of input records per cell. Count doesn't accept any arguments, so passing in vals on its own won't change that. First does accept arguments, so passing in vals=['cost'] will cause each cell to contain the first value of cost (ordered via "natural sort") per cell.
The first problem is that this function doesn't accept a values kwarg, but rather vals.
The second issue you'll face is that you'll need to specify an aggregation function (the default is Count) to summarize your values. This is sort of similar to the pandas pivot table's aggfunc argument. If you expect to only have a single value then something like pivot_ui(df, rows=['product'], cols=['region'], vals=['cost'], aggregatorName='First') should do the trick.
By way of explanation, your code above is just providing the Count of input records per cell. Count doesn't accept any arguments, so passing in vals on its own won't change that. First does accept arguments, so passing in vals=['cost'] will cause each cell to contain the first value of cost (ordered via "natural sort") per cell.
answered Nov 26 '18 at 3:58
nicolaskruchtennicolaskruchten
13.4k65071
13.4k65071
works perfectly !
– M. Page
Nov 26 '18 at 7:01
add a comment |
works perfectly !
– M. Page
Nov 26 '18 at 7:01
works perfectly !
– M. Page
Nov 26 '18 at 7:01
works perfectly !
– M. Page
Nov 26 '18 at 7:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472501%2fdisplaying-data-in-jupyter-pivottable-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown