Got an error while trying to “groupby” this protion through pandas in pythonwhat does these pandas group by statement does?Converting a Pandas GroupBy output from Series to DataFrameAdding new column to existing DataFrame in Python pandasDelete rows not present in all DataFrame in pandasPython for Data Analysis: Chp 2 Pg 38 “prop_cumsum” errorPandas error in python 3.5.1Pandas Key Error: 0 while plotting a seaborn boxplotNameError after show some data'str' object cannot be interpreted as an integer on groupbyHow to calculate distance between two points in 3D?Pandas resample memory error on AWS ubuntu?
Why don't modern jet engines use forced exhaust mixing?
Best model for precedence constraints within scheduling problem
Why do aircraft leave cruising altitude long before landing just to circle?
Are there any rules on how characters go from 0th to 1st level in a class?
Radix2 Fast Fourier Transform implemented in C++
Designing a prison for a telekinetic race
Will some rockets really collapse under their own weight?
A reccomended structured approach to self studying music theory for songwriting
μονάδαι as plural form of μονάς
What exactly happened to the 18 crew members who were reported as "missing" in "Q Who"?
What was the intention with the Commodore 128?
The Roommates' Dilemma
Replacing old plug-in 220V range with new hardwire 3-wire electric cooktop: remove outlet or add a plug?
Representing an indicator function: binary variables and "indicator constraints"
Does the Temple of the Gods spell nullify critical hits?
Programming a recursive formula into Mathematica and find the nth position in the sequence
How does the illumination of the sky from the sun compare to that of the moon?
Compute the square root of a positive integer using binary search
Have made several mistakes during the course of my PhD. Can't help but feel resentment. Can I get some advice about how to move forward?
Do I need to start off my book by describing the character's "normal world"?
What if a restaurant suddenly cannot accept credit cards, and the customer has no cash?
Is this bar slide trick shown on Cheers real or a visual effect?
Gofer work in exchange for Letter of Recommendation
What allows us to use imaginary numbers?
Got an error while trying to “groupby” this protion through pandas in python
what does these pandas group by statement does?Converting a Pandas GroupBy output from Series to DataFrameAdding new column to existing DataFrame in Python pandasDelete rows not present in all DataFrame in pandasPython for Data Analysis: Chp 2 Pg 38 “prop_cumsum” errorPandas error in python 3.5.1Pandas Key Error: 0 while plotting a seaborn boxplotNameError after show some data'str' object cannot be interpreted as an integer on groupbyHow to calculate distance between two points in 3D?Pandas resample memory error on AWS ubuntu?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to build a recommendation system and follow a tutorial. I'm trying to groupby these columns but I got a bunch of weird errors and I can't understand why.
import numpy as np
import pandas as pd
import math
import random
import sklearn
interactions_df = pd.read_csv('C:/Users/Rao/Desktop/Recommender System/users_interactions.csv')
interactions_df.head(3)
print(interactions_df.groupby(['personId', 'contentId']).size().groupby('personId').size())
I want this output:
print (interactions_df.groupby(['personId', 'contentId']).size())
personId contentId
W a 1
b 1
X a 2
Y a 2
Z a 1
b 1
dtype: int64
But I got:
TypeError Traceback (most recent call
last)
C:Program FilesAnaconda3libsite-packagespandasindexesmulti.py in
get_value(self, series, key)
617 try:
--> 618 return _index.get_value_at(s, k)
619 except IndexError:
pandasindex.pyx in pandas.index.get_value_at (pandasindex.c:2549)()
pandassrcutil.pxd in util.get_value_at (pandasindex.c:15951)()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call
last)
<ipython-input-25-22789f9d1e69> in <module>()
----> 1 print(interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
2 #print (interactions_df.groupby(['personId', 'contentId']).size())
3 #print (interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
C:Program FilesAnaconda3libsite-packagespandascoregeneric.py in
groupby(self, by, axis, level, as_index, sort, group_keys, squeeze,
**kwargs)
3776 return groupby(self, by=by, axis=axis, level=level,
as_index=as_index,
3777 sort=sort, group_keys=group_keys,
squeeze=squeeze,
-> 3778 **kwargs)
3779
3780 def asfreq(self, freq, method=None, how=None,
normalize=False):
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3332)()
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3035)()
pandasindex.pyx in pandas.index.IndexEngine.get_loc (pandasindex.c:4018)
()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12368)()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12322)()
KeyError: 'personId'
python pandas pandas-groupby recommendation-engine
|
show 1 more comment
I want to build a recommendation system and follow a tutorial. I'm trying to groupby these columns but I got a bunch of weird errors and I can't understand why.
import numpy as np
import pandas as pd
import math
import random
import sklearn
interactions_df = pd.read_csv('C:/Users/Rao/Desktop/Recommender System/users_interactions.csv')
interactions_df.head(3)
print(interactions_df.groupby(['personId', 'contentId']).size().groupby('personId').size())
I want this output:
print (interactions_df.groupby(['personId', 'contentId']).size())
personId contentId
W a 1
b 1
X a 2
Y a 2
Z a 1
b 1
dtype: int64
But I got:
TypeError Traceback (most recent call
last)
C:Program FilesAnaconda3libsite-packagespandasindexesmulti.py in
get_value(self, series, key)
617 try:
--> 618 return _index.get_value_at(s, k)
619 except IndexError:
pandasindex.pyx in pandas.index.get_value_at (pandasindex.c:2549)()
pandassrcutil.pxd in util.get_value_at (pandasindex.c:15951)()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call
last)
<ipython-input-25-22789f9d1e69> in <module>()
----> 1 print(interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
2 #print (interactions_df.groupby(['personId', 'contentId']).size())
3 #print (interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
C:Program FilesAnaconda3libsite-packagespandascoregeneric.py in
groupby(self, by, axis, level, as_index, sort, group_keys, squeeze,
**kwargs)
3776 return groupby(self, by=by, axis=axis, level=level,
as_index=as_index,
3777 sort=sort, group_keys=group_keys,
squeeze=squeeze,
-> 3778 **kwargs)
3779
3780 def asfreq(self, freq, method=None, how=None,
normalize=False):
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3332)()
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3035)()
pandasindex.pyx in pandas.index.IndexEngine.get_loc (pandasindex.c:4018)
()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12368)()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12322)()
KeyError: 'personId'
python pandas pandas-groupby recommendation-engine
Why are you callinggroupby
twice?
– Josh Friedlander
Mar 27 at 13:39
1
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is nopersonId
column in the dataframe...
– Serge Ballesta
Mar 27 at 13:57
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24
|
show 1 more comment
I want to build a recommendation system and follow a tutorial. I'm trying to groupby these columns but I got a bunch of weird errors and I can't understand why.
import numpy as np
import pandas as pd
import math
import random
import sklearn
interactions_df = pd.read_csv('C:/Users/Rao/Desktop/Recommender System/users_interactions.csv')
interactions_df.head(3)
print(interactions_df.groupby(['personId', 'contentId']).size().groupby('personId').size())
I want this output:
print (interactions_df.groupby(['personId', 'contentId']).size())
personId contentId
W a 1
b 1
X a 2
Y a 2
Z a 1
b 1
dtype: int64
But I got:
TypeError Traceback (most recent call
last)
C:Program FilesAnaconda3libsite-packagespandasindexesmulti.py in
get_value(self, series, key)
617 try:
--> 618 return _index.get_value_at(s, k)
619 except IndexError:
pandasindex.pyx in pandas.index.get_value_at (pandasindex.c:2549)()
pandassrcutil.pxd in util.get_value_at (pandasindex.c:15951)()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call
last)
<ipython-input-25-22789f9d1e69> in <module>()
----> 1 print(interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
2 #print (interactions_df.groupby(['personId', 'contentId']).size())
3 #print (interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
C:Program FilesAnaconda3libsite-packagespandascoregeneric.py in
groupby(self, by, axis, level, as_index, sort, group_keys, squeeze,
**kwargs)
3776 return groupby(self, by=by, axis=axis, level=level,
as_index=as_index,
3777 sort=sort, group_keys=group_keys,
squeeze=squeeze,
-> 3778 **kwargs)
3779
3780 def asfreq(self, freq, method=None, how=None,
normalize=False):
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3332)()
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3035)()
pandasindex.pyx in pandas.index.IndexEngine.get_loc (pandasindex.c:4018)
()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12368)()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12322)()
KeyError: 'personId'
python pandas pandas-groupby recommendation-engine
I want to build a recommendation system and follow a tutorial. I'm trying to groupby these columns but I got a bunch of weird errors and I can't understand why.
import numpy as np
import pandas as pd
import math
import random
import sklearn
interactions_df = pd.read_csv('C:/Users/Rao/Desktop/Recommender System/users_interactions.csv')
interactions_df.head(3)
print(interactions_df.groupby(['personId', 'contentId']).size().groupby('personId').size())
I want this output:
print (interactions_df.groupby(['personId', 'contentId']).size())
personId contentId
W a 1
b 1
X a 2
Y a 2
Z a 1
b 1
dtype: int64
But I got:
TypeError Traceback (most recent call
last)
C:Program FilesAnaconda3libsite-packagespandasindexesmulti.py in
get_value(self, series, key)
617 try:
--> 618 return _index.get_value_at(s, k)
619 except IndexError:
pandasindex.pyx in pandas.index.get_value_at (pandasindex.c:2549)()
pandassrcutil.pxd in util.get_value_at (pandasindex.c:15951)()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call
last)
<ipython-input-25-22789f9d1e69> in <module>()
----> 1 print(interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
2 #print (interactions_df.groupby(['personId', 'contentId']).size())
3 #print (interactions_df.groupby(['personId',
'contentId']).size().groupby('personId').size())
C:Program FilesAnaconda3libsite-packagespandascoregeneric.py in
groupby(self, by, axis, level, as_index, sort, group_keys, squeeze,
**kwargs)
3776 return groupby(self, by=by, axis=axis, level=level,
as_index=as_index,
3777 sort=sort, group_keys=group_keys,
squeeze=squeeze,
-> 3778 **kwargs)
3779
3780 def asfreq(self, freq, method=None, how=None,
normalize=False):
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3332)()
pandasindex.pyx in pandas.index.IndexEngine.get_value
(pandasindex.c:3035)()
pandasindex.pyx in pandas.index.IndexEngine.get_loc (pandasindex.c:4018)
()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12368)()
pandashashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item
(pandashashtable.c:12322)()
KeyError: 'personId'
python pandas pandas-groupby recommendation-engine
python pandas pandas-groupby recommendation-engine
edited Mar 27 at 13:38
Josh Friedlander
3,4432 gold badges11 silver badges36 bronze badges
3,4432 gold badges11 silver badges36 bronze badges
asked Mar 27 at 13:31
raobabarraobabar
42 bronze badges
42 bronze badges
Why are you callinggroupby
twice?
– Josh Friedlander
Mar 27 at 13:39
1
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is nopersonId
column in the dataframe...
– Serge Ballesta
Mar 27 at 13:57
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24
|
show 1 more comment
Why are you callinggroupby
twice?
– Josh Friedlander
Mar 27 at 13:39
1
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is nopersonId
column in the dataframe...
– Serge Ballesta
Mar 27 at 13:57
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24
Why are you calling
groupby
twice?– Josh Friedlander
Mar 27 at 13:39
Why are you calling
groupby
twice?– Josh Friedlander
Mar 27 at 13:39
1
1
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is no
personId
column in the dataframe...– Serge Ballesta
Mar 27 at 13:57
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is no
personId
column in the dataframe...– Serge Ballesta
Mar 27 at 13:57
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24
|
show 1 more comment
0
active
oldest
votes
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%2f55378463%2fgot-an-error-while-trying-to-groupby-this-protion-through-pandas-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
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%2f55378463%2fgot-an-error-while-trying-to-groupby-this-protion-through-pandas-in-python%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
Why are you calling
groupby
twice?– Josh Friedlander
Mar 27 at 13:39
1
If you get an error on a complex statement (here two groupby) make every call in sequence. It will be easier to find the cause for the error. Anyway the error suggest that there is no
personId
column in the dataframe...– Serge Ballesta
Mar 27 at 13:57
@SergeBallesta but my dataset has column named 'personId'. Anyway, I tried to write separate statements but same error occurred
– raobabar
Mar 27 at 14:17
@JoshFriedlander I follow this tutorial: kaggle.com/gspmoreira/… and Here stackoverflow.com/questions/52850214/… is a lil information about this line of code but I found errors while running this.
– raobabar
Mar 27 at 14:18
Print the head of the dataframe and show what you obtain. It could give a hint...
– Serge Ballesta
Mar 27 at 14:24