osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

format number is not recognized in a cycle


Dear all,

I have this dataframe:

datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
2012-01-01 06:00,  0.4,100, 911,321,  2.5,  0.0,   0,  0,0
2012-01-01 07:00,  0.8,100, 911,198,  0.8,  0.0,   0, 22,0
2012-01-01 08:00,  0.6,100, 912, 44,  1.2,  0.0,  30, 22,0
2012-01-01 09:00,  3.1, 76, 912, 22,  0.8,  0.0, 134, 44,0
2012-01-01 10:00,  3.4, 77, 912, 37,  0.5,  0.0, 191, 67,0
2012-01-01 11:00,  3.5,100, 912,349,  0.4,  0.0, 277, 44,0
2012-01-01 12:00,  3.6,100, 912, 17,  0.9,  0.0, 292, 22,0
2012-01-01 13:00,  3.5,100, 912, 28,  0.3,  0.0, 219, 44,0
2012-01-01 14:00,  3.3, 68, 912, 42,  0.5,  0.0, 151, 22,0

....
....

I would like to plot and analyse different part of it. Consequently I have created the following variables in order to manage different period:

start_date = np.array(['2012-01-01 06:00','2013-01-01 06:00','2014-01-01 06:00'])
end_date   = np.array(['2013-01-01 05:00','2014-01-01 05:00','2015-01-01 05:00'])

However, if I try to perform the following cycle:

for ii in range(0, 1):   
   pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,
   na_values=-999)
   df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), "%Y-%m-%d %H:%M"))
   #
   mask = (df['datatime'] > start_date[ii]) & (df['datatime'] <= end_date[ii])

I get the following error:

    return _get_dtype_type(np.dtype(arr_or_dtype))
  File "/usr/lib/python2.7/dist-packages/numpy/core/_internal.py", line 173, in _commastring
    (len(result)+1, astr))
ValueError: format number 1 of "2012-01-01 06:00" is not recognized



On the contrary, if I use the simple variables:
start_date = 2012-01-01 06:00
end_date   = 2013-01-01 05:00

without the cycle, it works.

I really do not understand why.

Thanks a lot,
Diego