You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I encountered a very strange bug when indexing pd.Series in Pandas groupby object.
if False:
df = pd.DataFrame({'app':['a', 'b', 'c', 'd', 'e'], 'sessionId':['1', '1', '2', '3', '3']},
index=['a1', 'a2', 'a3', 'a4', 'a5']) # this will not cause the last line to crash
else:
df = pd.DataFrame({'app': ['a', 'b', 'c', 'd', 'e'], 'sessionId': ['1', '1', '2', '3', '3']},
index=[1,2,3,4,5]) # this will cause the last line to crash
df1 = [v.app[0] for k, v in df.groupby('sessionId')] # the crashing line
As shown in the above code, if df.index elements are string, pd.Timestamp, etc., the last line will not crash; however, if df.index elements are int, float, etc., the last line will crash. Ridiculously, in both cases type(v.app) is pd.Series, yet one is index-able, while the other one is not. It is worth noting that the crashing line has not even touched df.index, so why does the value type of df.index elements matters?
So do we have another general inconsistency due to incompetent programming?
The text was updated successfully, but these errors were encountered:
Recently, I encountered a very strange bug when indexing pd.Series in Pandas groupby object.
As shown in the above code, if df.index elements are string, pd.Timestamp, etc., the last line will not crash; however, if df.index elements are int, float, etc., the last line will crash. Ridiculously, in both cases
type(v.app)
is pd.Series, yet one is index-able, while the other one is not. It is worth noting that the crashing line has not even touched df.index, so why does the value type of df.index elements matters?So do we have another general inconsistency due to incompetent programming?
The text was updated successfully, but these errors were encountered: