Re: Convert pandas series to string and datetime object
Pavol Lisy wrote: > pandas is one of reasons why python is so popular these days. But > "there is only milion way how to do it" (and other unpythonic issues) > I see there every time I am looking at it. :) Yeah, such a useful tool with such a byzantine API, completely at odds with the zen -- I wonder what prevented that the authors chose to write it in Perl ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert pandas series to string and datetime object
On 9/21/17, Peter Otten <__pete...@web.de> wrote: > zljubi...@gmail.com wrote: > >> I have sliced the pandas dataframe >> >> end_date = df[-1:]['end'] >> >> type(end_date) >> Out[4]: pandas.core.series.Series >> >> end_date >> Out[3]: >> 48173 2017-09-20 04:47:59 >> Name: end, dtype: datetime64[ns] >> >> 1. How to get rid of index value 48173 and get only "2017-09-20 > 04:47:59" >> string? I have to call REST API with "2017-09-20 04:47:59" as a >> parameter, >> so I have to get string from pandas datetime64 series. >> 2. How to get rid of index value 48173 and get only datetime object >> [something like datetime.datetime.strptime('2017-09-20 04:47:59', >> '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 >> 04:47:59' >> < datetime.datetime(2017,1,9) >> >> How to do these conversions? > > After a web search and some trial and error: > d = pd.DataFrame([[1, datetime.datetime.now()], [2, > datetime.datetime.now()]], columns=["whatever", "end"]) d >whateverend > 0 1 2017-09-21 22:36:52.342757 > 1 2 2017-09-21 22:36:52.349973 > > [2 rows x 2 columns] d["end"].astype(datetime.datetime).values[-1] > datetime.datetime(2017, 9, 21, 22, 36, 52, 349973) Or: >>> d.iloc[-1]['end'].strftime('%Y-%m-%d %H:%M:%S') '2017-09-22 09:03:40' PS. pandas is one of reasons why python is so popular these days. But "there is only milion way how to do it" (and other unpythonic issues) I see there every time I am looking at it. :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert pandas series to string and datetime object
zljubi...@gmail.com wrote: > I have sliced the pandas dataframe > > end_date = df[-1:]['end'] > > type(end_date) > Out[4]: pandas.core.series.Series > > end_date > Out[3]: > 48173 2017-09-20 04:47:59 > Name: end, dtype: datetime64[ns] > > 1.How to get rid of index value 48173 and get only "2017-09-20 04:47:59" > string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, > so I have to get string from pandas datetime64 series. > 2.How to get rid of index value 48173 and get only datetime object > [something like datetime.datetime.strptime('2017-09-20 04:47:59', > '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' > < datetime.datetime(2017,1,9) > > How to do these conversions? After a web search and some trial and error: >>> d = pd.DataFrame([[1, datetime.datetime.now()], [2, datetime.datetime.now()]], columns=["whatever", "end"]) >>> d whateverend 0 1 2017-09-21 22:36:52.342757 1 2 2017-09-21 22:36:52.349973 [2 rows x 2 columns] >>> d["end"].astype(datetime.datetime).values[-1] datetime.datetime(2017, 9, 21, 22, 36, 52, 349973) -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert pandas series to string and datetime object
On 2017-09-21 20:27, zljubi...@gmail.com wrote: I have sliced the pandas dataframe end_date = df[-1:]['end'] type(end_date) Out[4]: pandas.core.series.Series end_date Out[3]: 48173 2017-09-20 04:47:59 Name: end, dtype: datetime64[ns] 1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59" string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, so I have to get string from pandas datetime64 series. 2. How to get rid of index value 48173 and get only datetime object [something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < datetime.datetime(2017,1,9) How to do these conversions? The docs say that pandas.Series is "One-dimensional ndarray with axis labels (including time series)", so have you tried indexing, such as end_date[1]? -- https://mail.python.org/mailman/listinfo/python-list
Convert pandas series to string and datetime object
I have sliced the pandas dataframe end_date = df[-1:]['end'] type(end_date) Out[4]: pandas.core.series.Series end_date Out[3]: 48173 2017-09-20 04:47:59 Name: end, dtype: datetime64[ns] 1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59" string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, so I have to get string from pandas datetime64 series. 2. How to get rid of index value 48173 and get only datetime object [something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < datetime.datetime(2017,1,9) How to do these conversions? -- https://mail.python.org/mailman/listinfo/python-list