I am having trouble converting a python datetime64
object into a string. For example:
t = numpy.datetime64('2012-06-30T20:00:00.000000000-0400')
Into:
'2012.07.01' as a string. (note time difference)
I have already tried to convert the datetime64
object to a datetime
long then to a string, but I seem to get this error:
dt = t.astype(datetime.datetime) #1341100800000000000L time.ctime(dt) ValueError: unconvertible time
You can use Numpy's datetime_as_string function. The unit='D' argument specifies the precision, in this case days. numpy instead of numpyp . Or with import numpy as np just np.
With the help of numpy. datetime64() method, we can get the date in a numpy array in a particular format i.e year-month-day by using numpy. datetime64() method. Syntax : numpy.datetime64(date) Return : Return the date in a format 'yyyy-mm-dd'.
NumPy's datetime64 and timedelta64 objectsNumPy has no separate date and time objects, just a single datetime64 object to represent a single moment in time. The datetime module's datetime object has microsecond precision (one-millionth of a second).
Solution was:
import pandas as pd ts = pd.to_datetime(str(date)) d = ts.strftime('%Y.%m.%d')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With