Group Abstract Group Abstract

Message Boards Message Boards

1
|
7.3K Views
|
6 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Extract data from a list based on the time interval

POSTED BY: M.A. Ghorbani
6 Replies

Hello Mohammad,

maybe the easiest way is to create a nested association from your data:

as = Merge[#, Identity] & /@ Apply[Association@*Rule, Merge[{Round@list1, list2}, Transpose], {2}];

(Note that your year numbers should all be integers (for being used as keys), therefore I write Round@list1.) With this you can ask questions like:

What happened in Manitoba 2014?

as["Manitoba", 2014]

Which years have all cities in common?

intersec = Intersection @@ Keys[Values@as]

What are the data for the years 2015 until 2017?

as[[All, Key /@ Range[2015, 2017]]]

What are the data for the common years?

as[[All, Key /@ intersec]]

Does that help? Regards -- Henrik

POSTED BY: Henrik Schachner

Henrik,

That's great work. Thank you so much.

Could you please have a look at the enclosed file.

Attachments:
POSTED BY: M.A. Ghorbani

Dear Mohammad,

The problem is that you do not have clean data: Most of the year numbers in list1 are strings, only some are numbers, and similar with the data values in list2. So I simply changed all to numbers, and now it seems to work.

Regards -- Henrik

Attachments:
POSTED BY: Henrik Schachner
Posted 6 years ago
POSTED BY: Rohit Namjoshi

Dear Rohit and Henrik,

I really appreciate your kindness and help to solve the problem.

I did somethings according to your solution way and got the final list at the last. For example; the first station "ACIPAYAM" has the incomplete data in 1977 and the missing data in 1978 as below:

1977 -> {73.6, 40.2}, 1978 -> Missing["KeyAbsent", 1978].

The second or "ADANA BÖLGE" station has the full record. Now, how do I extract the list of stations with full records? Is it possible to plot the time series for one of the stations with the full record?

Attachments:
POSTED BY: M.A. Ghorbani
Posted 6 years ago

Hi Mohammad,

What is the definition of "full record"? Some years have 12 items, some have 13, in many cases the last item for a year is equal to the sum of the previous items in the year (as I pointed out earlier), is that last item part of the "full record"?

J["ACIPAYAM"] // Map[Length]

J["ACIPAYAM"] // DeleteMissing // Map[(Total@Most@# - Last@#) & /* Chop]

The data can be plotted in many ways, it is not clear to me what you mean by "plot the time series"? What is the time dimension?

J["ACIPAYAM"] // DeleteMissing //
 BarChart[#,
   ChartLabels -> Automatic,
   ImageSize -> 1000,
   AspectRatio -> 1/3,
   ColorFunction -> "Rainbow"] &
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard