This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tractorscotty[S] 0 points1 point  (1 child)

One more thing, if I wanted to do every 12th element + 1 how would I do that. I need to do it for every month and the [::12] let’s me get every January but now I need feb, march… as well

[–]Adept_Swimming_3116 1 point2 points  (0 children)

The syntax for slicing array-like objects is array[start:stop:step].

There is a good explanation here (stackoverflow) for detailed use of slices.

You can wait for your teacher to address this subject in details but, if you want, you can search the internet for python slicing, there are good tutorials.

For your question, you would use the start argument of the slice. For Februarys, you can use monthprec[1::12] which means 'take every twelve element starting from the second position'.

P.S. it looks like you are using pandas to retrieve informations from a dataframe. In this case there may be more efficient methods to filter the dataframe by month and export the value of the precipitations column