I have two arrays with datetime objects, but I need only one combined array with date of the first and time of the second.. If I use
datetime.combine(date,time)
the result is
TypeError: combine() argument 1 must be datetime.date, not numpy.ndarray
the code is:
import numpy as np
import matplotlib.pyplot as pp
import math
from datetime import datetime, time, date
from glob import glob
import pylab as plb
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
#importo i nomi dei files
fnames=glob('C:/Users/asus/Desktop/lab_astro/GALASSIA/galassia canale 43/*')
#conto i files per ogni tipo e inizializzo le variabili dove mettere i dati
num_file14=len(fnames)
signal14=[]
dt = datetime
dd = datetime
#leggo i files e riempio le variabiliChange working directory..
for n in range (0, num_file14):
data14=np.loadtxt(fnames[n], comments ='END', delimiter=';', skiprows=1, usecols=(0,1,7),dtype=object,converters={ 0: lambda x: dd.strptime(x, "%d/%m/%Y"),1: lambda x: dt.strptime(x, "%H.%M.%S") , 7: np.float})
dd=np.append(orario,data14[:,0])
dt=np.append(orario,data14[:,1])
d = datetime.combine(dd,dt)
signal14=np.append(signal14,data14[:,2])
maby my question is naive, I'm new in Python, but I really need this program to work...thanks for your help!!
Your variables dd and dt are in numpy.ndarray format. It's need to convert to datetime format.
Look at the working of datetime.combine(date,time)
In [1]: import datetime
In [2]: time = datetime.time(12,12,12)
In [3]: date = datetime.date(2015,1,04)
In [4]: datetime.datetime.combine(date,time)
Out[1]: datetime.datetime(2015, 1, 4, 12, 12, 12)
I hope dd represent for date and dt represent for time. So your code changed like this.
datetime.datetime.combine(dd.date(),dt.time())
If you are using iteration. You have to change the code as per the iteration
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