lists vs. NumPy arrays for sets of dates and strings

Denis McMahon denismfmcmahon at gmail.com
Mon Jun 9 16:50:03 EDT 2014


On Mon, 09 Jun 2014 12:48:12 -0700, beliavsky wrote:

> I am going to read a multivariate time series from a CSV file that looks
> like
> 
> Date,A,B 2014-01-01,10.0,20.0 2014-01-02,10.1,19.9 ...
> 
> The numerical data I will store in a NumPy array, since they are more
> convenient to work with than lists of lists. What are the advantages and
> disadvantages of storing the symbols [A,B] and dates
> [2014-01-01,2014-01-02] as lists vs. NumPy arrays?

You could also use a dictionary of either lists or tuples or even NumPy 
arrays keyed on the date.

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> x = {}
>>> y = numpy.array( [0,1] )
>>> x['2014-06-05'] = y
>>> x['2014-06-05']
array([0, 1])
>>> x
{'2014-06-05': array([0, 1])}
>>> x['2014-06-05'][0]
0
>>> x['2014-06-05'][1]
1

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list