Find mean of means using pandas in excel file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
My excel file is set up with data like this:
REV PU LOC DEL LOC MILES RPM
3500 SANTA ANA SAN DIEGO 160 21.875
Having many (500+) of similar lines of data. I want to find the common pu/del loc and their average rpm's. So, if there are 5 different entries of the above line, I want to use pandas to average their RPM values and then output that as the only value listed with the pu loc and del loc in a seperate excel file. The line I am attempting to do this with is
df = df.groupby(['PU LOC', 'DEL LOC', 'RPM']).mean(axis={index(0), columns(3)})
Although it does not work, I feel like I am on the right track. Any help is much appreciated!
python pandas dataframe pandas-groupby
add a comment |
My excel file is set up with data like this:
REV PU LOC DEL LOC MILES RPM
3500 SANTA ANA SAN DIEGO 160 21.875
Having many (500+) of similar lines of data. I want to find the common pu/del loc and their average rpm's. So, if there are 5 different entries of the above line, I want to use pandas to average their RPM values and then output that as the only value listed with the pu loc and del loc in a seperate excel file. The line I am attempting to do this with is
df = df.groupby(['PU LOC', 'DEL LOC', 'RPM']).mean(axis={index(0), columns(3)})
Although it does not work, I feel like I am on the right track. Any help is much appreciated!
python pandas dataframe pandas-groupby
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add'RPM'
in yourgroupby
.
– busybear
Jan 3 at 22:47
add a comment |
My excel file is set up with data like this:
REV PU LOC DEL LOC MILES RPM
3500 SANTA ANA SAN DIEGO 160 21.875
Having many (500+) of similar lines of data. I want to find the common pu/del loc and their average rpm's. So, if there are 5 different entries of the above line, I want to use pandas to average their RPM values and then output that as the only value listed with the pu loc and del loc in a seperate excel file. The line I am attempting to do this with is
df = df.groupby(['PU LOC', 'DEL LOC', 'RPM']).mean(axis={index(0), columns(3)})
Although it does not work, I feel like I am on the right track. Any help is much appreciated!
python pandas dataframe pandas-groupby
My excel file is set up with data like this:
REV PU LOC DEL LOC MILES RPM
3500 SANTA ANA SAN DIEGO 160 21.875
Having many (500+) of similar lines of data. I want to find the common pu/del loc and their average rpm's. So, if there are 5 different entries of the above line, I want to use pandas to average their RPM values and then output that as the only value listed with the pu loc and del loc in a seperate excel file. The line I am attempting to do this with is
df = df.groupby(['PU LOC', 'DEL LOC', 'RPM']).mean(axis={index(0), columns(3)})
Although it does not work, I feel like I am on the right track. Any help is much appreciated!
python pandas dataframe pandas-groupby
python pandas dataframe pandas-groupby
asked Jan 3 at 22:44
z.rubiz.rubi
346
346
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add'RPM'
in yourgroupby
.
– busybear
Jan 3 at 22:47
add a comment |
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add'RPM'
in yourgroupby
.
– busybear
Jan 3 at 22:47
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add
'RPM'
in your groupby
.– busybear
Jan 3 at 22:47
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add
'RPM'
in your groupby
.– busybear
Jan 3 at 22:47
add a comment |
2 Answers
2
active
oldest
votes
To expand on the other answer, this should get you close to your expected output:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean().reset_index()
Side note: is the arithmetic mean of RPM
really what you need, or would it make more sense to weight mean RPM by the number of miles covered at each RPM value?
add a comment |
You should not include RPM
in the groupby.
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.
– Polkaguy6000
Jan 3 at 22:55
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%2f54030830%2ffind-mean-of-means-using-pandas-in-excel-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To expand on the other answer, this should get you close to your expected output:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean().reset_index()
Side note: is the arithmetic mean of RPM
really what you need, or would it make more sense to weight mean RPM by the number of miles covered at each RPM value?
add a comment |
To expand on the other answer, this should get you close to your expected output:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean().reset_index()
Side note: is the arithmetic mean of RPM
really what you need, or would it make more sense to weight mean RPM by the number of miles covered at each RPM value?
add a comment |
To expand on the other answer, this should get you close to your expected output:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean().reset_index()
Side note: is the arithmetic mean of RPM
really what you need, or would it make more sense to weight mean RPM by the number of miles covered at each RPM value?
To expand on the other answer, this should get you close to your expected output:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean().reset_index()
Side note: is the arithmetic mean of RPM
really what you need, or would it make more sense to weight mean RPM by the number of miles covered at each RPM value?
answered Jan 3 at 23:28
Peter LeimbiglerPeter Leimbigler
4,8131416
4,8131416
add a comment |
add a comment |
You should not include RPM
in the groupby.
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.
– Polkaguy6000
Jan 3 at 22:55
add a comment |
You should not include RPM
in the groupby.
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.
– Polkaguy6000
Jan 3 at 22:55
add a comment |
You should not include RPM
in the groupby.
You should not include RPM
in the groupby.
answered Jan 3 at 22:49
Polkaguy6000Polkaguy6000
693513
693513
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.
– Polkaguy6000
Jan 3 at 22:55
add a comment |
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.
– Polkaguy6000
Jan 3 at 22:55
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
Forgive my ignorance but I thought that if i didnt include that, the RPM field would not be included in the new excel file
– z.rubi
Jan 3 at 22:52
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
You should try the code. It will not be included in the index, but it will be included in the result.
– Polkaguy6000
Jan 3 at 22:53
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.– Polkaguy6000
Jan 3 at 22:55
Also, and this is not necessary, if you only wanted the average of RPM, you could just write:
df = df.groupby(['PU LOC', 'DEL LOC']).RPM.mean()
.– Polkaguy6000
Jan 3 at 22:55
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%2f54030830%2ffind-mean-of-means-using-pandas-in-excel-file%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
How does it not work? Are you getting an error? Or an unexpected result? My guess is that you do not need to add
'RPM'
in yourgroupby
.– busybear
Jan 3 at 22:47