[SciPy-User] pandas: strange result using df.date.tolist

Jeff Reback jreback@yahoo....
Thu Jun 20 14:35:11 CDT 2013


this is a numpy < 1.7.0 issue, see here (a little down):

http://pandas.pydata.org/pandas-docs/dev/whatsnew.html#potential-porting-issues-for-pandas-0-7-3-users


values are usable, just a printing issue
 
In [2]: x = [datetime.datetime(2013, 1, 15, 13, 56, 44), datetime.datetime(2013, 1, 
18, 8, 17, 13), datetime.datetime(2013, 1, 18, 9, 17, 13), 
datetime.datetime(2013, 1, 23, 11, 12, 2), datetime.datetime(2013, 1, 
28, 9, 21, 12)]

In [4]: Series(x).values

Out[4]: 
array(['2013-01-15T08:56:44.000000000-0500',
       '2013-01-18T03:17:13.000000000-0500',
       '2013-01-18T04:17:13.000000000-0500',
       '2013-01-23T06:12:02.000000000-0500',
       '2013-01-28T04:21:12.000000000-0500'], dtype='datetime64[ns]')

In [5]: np.__version__
Out[5]: '1.7.1'


-------------------------------

In [3]: np.__version__
Out[3]: '1.6.1'

In [5]: x = [datetime.datetime(2013, 1, 15, 13, 56, 44), datetime.datetime(2013, 1, 
   ...: 18, 8, 17, 13), datetime.datetime(2013, 1, 18, 9, 17, 13), 
   ...: datetime.datetime(2013, 1, 23, 11, 12, 2), datetime.datetime(2013, 1, 
   ...: 28, 9, 21, 12)]

In [7]: pd.Series(x).values
Out[7]: 
array([1970-01-16 141:56:44, 1970-01-16 208:17:13, 1970-01-16 209:17:13,
       1970-01-16 75:12:02, 1970-01-16 193:21:12], dtype=datetime64[ns])


________________________________
 From: elmar werling <elmar@net4werling.de>
To: scipy-user@scipy.org 
Sent: Thursday, June 20, 2013 3:23 PM
Subject: [SciPy-User] pandas: strange result using df.date.tolist
 

Hello,

I get rather strage results using pandas "tolist" with date time values. 
As an examples 2013-01-15 13:56:44 is converted to 1970-01-16 141:56:44.

The following script:
--------------------------------------------------------------
import pandas as pd
from datetime import datetime

file_name = 'test_file.xlsx'
reader = pd.ExcelFile(file_name)
sheets = reader.sheet_names
df = reader.parse(sheets[0], header=0,parse_cols='A,B')

date = []
for i in range(len(df)):
     yr = df.date[i].year
     mo = df.date[i].month
     dy = df.date[i].day
     hr = df.time[i].hour
     mi = df.time[i].minute
     sc = df.time[i].second
     _date = datetime(yr, mo, dy, hr, mi, sc)
     date.append(_date)

df['date2'] = date

print 'date from list'
print date
print
print 'date from pd.DataFrame'
print df['date2']
print
print 'date from df.date.values'
print df.date2.values
print
print 'pandas version: ', pd.__version__

--------------------------------------------------------------
gives

--------------------------------------------------------------
Python 2.7.3 (default, Jan  2 2013, 13:56:14)
[GCC 4.7.2] on linux2
Type "copyright", "credits" or "license()" for more information.

>>>

date from list
[datetime.datetime(2013, 1, 15, 13, 56, 44), datetime.datetime(2013, 1, 
18, 8, 17, 13), datetime.datetime(2013, 1, 18, 9, 17, 13), 
datetime.datetime(2013, 1, 23, 11, 12, 2), datetime.datetime(2013, 1, 
28, 9, 21, 12)]

date from pd.DataFrame
0   2013-01-15 13:56:44
1   2013-01-18 08:17:13
2   2013-01-18 09:17:13
3   2013-01-23 11:12:02
4   2013-01-28 09:21:12
Name: date2, dtype: datetime64[ns]

date from df.date.values
[1970-01-16 141:56:44 1970-01-16 208:17:13 1970-01-16 209:17:13
  1970-01-16 75:12:02 1970-01-16 193:21:12]

pandas version:  0.11.0

--------------------------------------------------------------

Any help is wellcome
Elmar

_______________________________________________
SciPy-User mailing list
SciPy-User@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130620/bb487f7f/attachment-0001.html 


More information about the SciPy-User mailing list