[AstroPy] Pandas Series times to MJD

Peter Weilbacher pweilbacher at aip.de
Sat Oct 20 04:19:55 EDT 2018


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



More information about the AstroPy mailing list