I have a numpy.ndarray thats values are pandas._libs.tslib.Timestamp
Example:
In: type(closedDate)
Out: numpy.ndarray
In: type(closedDate[0])
Out: pandas._libs.tslib.Timestamp
I would like to convert the contents of closedDate into a list of datetime.date
I have tried the following:
for i in closedDate:
closedDate[i].to_datetime()
But get this error:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
What to do? :/
closedDate.valueswould raise an error @Ami Tavory also the existing question of this deals with pandas df at first, whereas mine is a numpy array, so it is not a duplicate :Ppd.to_datetime(closedDate, unit='s')ValueError: non convertible value 2017-09-25 14:39:00with the unit 's'i get this error @Ami Tavoryfor cd in closedDate: cd.to_datetime()orfor i in range(len(closedDate)): closedDate[i].to_datetime(). However, none oft these loops would be meaningful as the values aren't saved in a list vor wherever, just calculated for nothing. And besides: such loops are best written with one thing I really linke in Python:for i, cd in enumerate(closedDate): ...- this provides you both the elements and the indices in your loop.