Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nth() mixes column order #20760

Closed
sursu opened this issue Apr 20, 2018 · 1 comment · Fixed by #22811
Closed

nth() mixes column order #20760

sursu opened this issue Apr 20, 2018 · 1 comment · Fixed by #22811
Labels
Bug Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@sursu
Copy link
Contributor

sursu commented Apr 20, 2018

Consider the following dataframe:

df = pd.DataFrame([[179293473,'2016-06-01 00:00:03.549745','http://www.dr.dk/nyheder/',39169523],[179293473,'2016-06-01 00:04:22.346018','https://www.information.dk/indland/2016/05/hvert-tredje-offer-naar-anmelde-voldtaegt-tide', 39125224],
 [179773461, '2016-06-01 22:13:16.588146', 'https://www.google.dk', 31658124],
 [179773461, '2016-06-01 22:14:04.059781', 'https://www.google.dk', 31658124],
 [179773461, '2016-06-01 22:16:37.230587', np.nan, 31658124],
 [179773461, '2016-06-01 22:23:09.847149', 'https://www.google.dk', 32718401],
 [179773461, '2016-06-01 22:23:55.158929', np.nan, 32718401],
 [179773461, '2016-06-01 22:27:00.857224', np.nan, 32718401]],
columns=['SessionID', 'PageTime', 'ReferrerURL', 'PageID'])

which looks like this:

 SessionID PageTime ReferrerURL PageID
179293473 2016-06-01 00:00:03.549745 http://www.dr.dk/nyheder/ 39169523
179293473 2016-06-01 00:04:22.346018 https://www.information.dk/ 39125224
179773461 2016-06-01 22:13:16.588146 https://www.google.dk 31658124
179773461 2016-06-01 22:14:04.059781 https://www.google.dk 31658124
179773461 2016-06-01 22:16:37.230587 NaN 31658124
179773461 2016-06-01 22:23:09.847149 https://www.google.dk 32718401
179773461 2016-06-01 22:23:55.158929 NaN 32718401
179773461 2016-06-01 22:27:00.857224 NaN 32718401

Run:
df.groupby('SessionID').nth(-1)

Out:

 SessionID PageID PageTime ReferrerURL
179293473 39125224 2016-06-01 00:04:22.346018 https://www.information.dk/
179773461 32718401 2016-06-01 22:27:00.857224 NaN

Question: Why has nth() mixed the order of my columns?

@ron819
Copy link

ron819 commented Aug 9, 2018

@mroeschke @jreback
Not sure if this is a bug but it would be nice if the nth() won't change the orders of the columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants