Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73058
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: lists vs. NumPy arrays for sets of dates and strings |
| Date | 2014-06-09 20:50 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ln56lr$93m$1@dont-email.me> (permalink) |
| References | <9b60eed1-1924-43d8-a92c-43b792118ebb@googlegroups.com> |
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@gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
lists vs. NumPy arrays for sets of dates and strings beliavsky@aol.com - 2014-06-09 12:48 -0700 Re: lists vs. NumPy arrays for sets of dates and strings Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-09 20:50 +0000 Re: lists vs. NumPy arrays for sets of dates and strings Peter Otten <__peter__@web.de> - 2014-06-10 09:18 +0200
csiph-web