Cannot convert Python list to timeSeries

I tried to solve this problem for more than one day. I have this type of list:

TempList[:5]
[(datetime.datetime(2015, 11, 25, 7, 29, 28, 337000),), (datetime.datetime(2015, 9, 8, 7, 44, 55, 53000),), (datetime.datetime(2015, 9, 10, 5, 44, 51, 867000),), (datetime.datetime(2015, 9, 10, 1, 42, 15, 740000),), (datetime.datetime(2015, 9, 2, 1, 7, 09, 687000),)]

I would like to convert it to the Pandas Time Series . I found this useful function : pd.to_datetime . But when I try to convert it:

Dates = pd.to_datetime(TempList)

I got this error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pandas/util/decorators.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tseries/tools.py", line 291, in to_datetime
    unit=unit, infer_datetime_format=infer_datetime_format)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tseries/tools.py", line 427, in _to_datetime
    return _convert_listlike(arg, box, format)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tseries/tools.py", line 341, in _convert_listlike
    raise TypeError('arg must be a string, datetime, list, tuple, '
TypeError: arg must be a string, datetime, list, tuple, 1-d array, or Series

But TempList is a list! I donโ€™t understand how to solve this. How can I convert my list? Thank!

+4
source share
1 answer

You have a list of tuples. Try converting this to a simple list, and then using pd.to_datetime. Something like (I don't have python right now)

tl2 = [ ti[0] for ti in TempList ]
Dates = pd.to_datetime(tl2)

PS1: TempList? ( 5 ).

PS2: format, . fooobar.com/questions/108863/....

+3

Source: https://habr.com/ru/post/1652748/


All Articles