arrays - removing duplicate values in python -
This question is already an answer here
- 2 replies
give me Columns are Excel Date and Temporary will look like this:
date temp 20130102 34,20 20130102 34.42 20130102 34.33 20130102 34,12 20130102 34,84 20130103 34,48 20130103 34.42 20130103 33 , 77 20130103 33,62 20130103 33,94 20130103 33,45
When I extract them into python using numpy, I get 2 arrays like this:
date = [20130102,20130102,20130102,20130102,20130102,20130103,20130103,20130103,20130103] temporary = [34.20,34.42,34.23 ....., 33.45]
< P> How do I convert this into array 1 of arrays, by combining the 1 date with all corresponding temps for that date? dataarray = [[20130102,34.20,34.42,34.23,34.12,34.84], [20130103,34.48,34.42,33.77,33.62,33.94,33.45]]
To get the exact format you specify (list of lists), I use and then to understand some links Open group generator for:
import itertools groups = itertools.groupby (zip (date, floating), lambda DV: DV [0]) list_of_lists = [[d] [v [1] Values in V] for D, value in the group]
I assume on the basis of your example, that come Data groupby
function will not need to do so, and you'd be better off with a dictionary (see below).
But my guess is, if you want to do something after actually opening it with this data do , then it is more convenient in a dictionary than the date To go with the strategy in which case you would like to go.
Comments
Post a Comment