[AstroPy] Pandas Series times to MJD

Wilfred Tyler Gee wtylergee at gmail.com
Sat Oct 20 15:34:26 EDT 2018


Hi Nic,

The problem is that the `dtype` is a `datetime64`, not just a `datetime`.
Looks like support is coming in 3.1. Issue:
https://github.com/astropy/astropy/pull/7361.

Problem discussed here: https://github.com/astropy/astropy/issues/6428
Gist solution here (from above):
https://gist.github.com/vn-ki/28edbc581b1218118b40df29855d1c6c

Cheers,

On Sat, Oct 20, 2018 at 7:37 PM Peter Weilbacher <pweilbacher at aip.de> wrote:

> Hi Nic,
>
> maybe you need to filter out the NaN / NaT values before passing them to
> Time?
>
>    Peter.
>
> P.S.: Sorry for sending some rubbish a few minutes ago...
>
> On 20.10.18 03:53, Nicholas Ross wrote:
> > Hi Astropy,
> >
> > Many thanks to Peter, Harry and David for their responses to discussions
> on the
> > intelligent averaging of time series data. I’ve been digging there and
> will share
> > results on my GitHub when there’s something to encouraging to report!
> >
> > The current issues is I’m struggling again with something that despite
> first inspection,
> > seems to be a wee bit annoying! I’d like to read-in some data, using
> e.g. pandas,
> > and then simply take the timestamp information and convert to an MJD.
> >
> >     import pandas as pd
> >     import numpy as np
> >     from astropy.time import Time
> >
> >     # Read in the data
> >     df = pd.read_csv(infile)
> >
> >     # first 5 elements of the timestamp column
> >     df['timestamp'][0:5]
> >
> >       0                     NaN
> >       1    2017-07-23T00:26:50Z
> >       2                     NaN
> >       3    2017-07-31T04:07:24Z
> >       4                     NaN
> >
> >     datetime = pd.to_datetime(df['timestamp'])
> >     print(datetime[0:5])
> >       0                   NaT
> >       1   2017-07-23 00:26:50
> >       2                    NaT
> >       3   2017-07-31 04:07:24
> >       4                   NaT
> >     Name: 'timestamp, dtype: datetime64[ns]
> >
> >    ## Then if I try:
> >    t = Time(df[‘timestamp', format='isot', scale='utc’)
> >    ## or
> >    t = Time(datetime, format='isot', scale='utc’)
> >
> > both give::
> >       ValueError: Input values did not match the format class isot
> > I’ve looked into julian (https://pypi.org/project/julian/) but run into
> > the same issues. What basic thing am I doing wrong??!!!
> >
> > Best,
> > Nic
>
> --
> Dr. Peter M. Weilbacher             http://www.aip.de/People/PWeilbacher
> Phone +49 331 74 99-667                       encryption key ID 7D6B4AA0
> ------------------------------------------------------------------------
> Leibniz-Institut für Astrophysik Potsdam (AIP)
> An der Sternwarte 16, D-14482 Potsdam
>
> Vorstand: Prof. Dr. Matthias Steinmetz, Matthias Winker
> Stiftung bürgerlichen Rechts, Stiftungsverz. Brandenburg: 26 742-00/7026
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>


-- 
~Wilfred Tyler Gee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20181021/63bb7bfd/attachment.html>


More information about the AstroPy mailing list