Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:03:27+00:00 2026-06-15T01:03:27+00:00

Suppose I have the following DataFrame (timeseries, first column is a DateTimeIndex) atn file

  • 0

Suppose I have the following DataFrame (timeseries, first column is a DateTimeIndex)

                           atn   file
datetime                             
2012-10-08 14:00:00  23.007462      1
2012-10-08 14:30:00  27.045666      1
2012-10-08 15:00:00  31.483825      1
2012-10-08 15:30:00  37.540651      2
2012-10-08 16:00:00  43.564573      2
2012-10-08 16:00:00  48.589852      2
2012-10-08 16:00:00  55.289452      2

My goal is to to extract the rows with the first appearance of a certain number in the last column ‘file’, so to obtain a table similar to this:

       datetime             atn
file                             
1      2012-10-08 14:00:00  23.007462
2      2012-10-08 15:30:00  37.540651

My approach was to groupby ‘file’ and then aggregate on ‘first’:

dt.groupby(by="file").aggregate("first")

But the problem with this is that then the index is not used as a column which is grouped. I solved this by first adding the index as a column by:

dt2 = dt.reset_index()
dt2.groupby(by="file").aggregate("first")

But now the problem is that the datetime column aren’t dates anymore but floats:

          datetime        atn
file                         
1     1.349705e+18  23.007462
2     1.349710e+18  37.540651

Is there

  • a way to convert the floats back to a datetime?
  • OR a way to preserve the datetimes in the groupby/aggregate-operation?
  • OR a better way to achieve this the final tabel?

The example dataframe can be used as follows:

Copy this (to clipboard):

2012-10-08 14:00:00,  23.007462,     1
2012-10-08 14:30:00,  27.045666,     1
2012-10-08 15:00:00,  31.483825,     1
2012-10-08 15:30:00,  37.540651,     2
2012-10-08 16:00:00,  43.564573,     2
2012-10-08 16:00:00,  48.589852,     2
2012-10-08 16:00:00,  55.289452,     2

And then:

dt = pandas.read_clipboard(sep=",", parse_dates=True, index_col=0, 
                           names=["datetime", "atn", "file"])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:03:28+00:00Added an answer on June 15, 2026 at 1:03 am

    I assume this is a bug in pandas – the dtype is changed to a float after the groupby

    dt3 = dt2.groupby(by="file").aggregate("first")
    dt3.dtypes
    

    Gives me:

    datetime    float64
    atn         float64
    

    To change the dtype back to datetime64 you can do:

    dt3['datetime'] = pd.Series(dt3['datetime'], dtype='datetime64[ns]')
    

    I have created a new issue on GitHub

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following list: ID3_tag = ['Title','Artist','Album','Track'] And I have a file
Suppose I have the following dataframe: df <- data.frame(BR.a=rnorm(10), BR.b=rnorm(10), BR.c=rnorm(10), USA.a=rnorm(10), USA.b =
Suppose I have a DataFrame which has a subindex structure like the following, with
Possible Duplicate: Drop Columns R Data frame Suppose, I have the following dataframe, and
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following simple struct: struct Vector3 { double x; double y;
Suppose I have the following js code: r='d|daa|dd'; reg = /\|.*/; result = reg.exec(r);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.