Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Help. Scenario: You have a data set that is about ~ 20000 values long. You want to create a loop that starts at

Python 3 Help.

Scenario: You have a data set that is about ~ 20000 values long. You want to create a loop that starts at the 1st data point and calculates the trend over 15 years. NOW the challenge is that you want to rerun through this data set, but instead of starting at 1, you start at 2 and calculate the trend over 15 years etc etc. To simplify, dates 0-15 --> calculate trend , dates 16-30 calculate trend ....all the way till the end then you start over BUT instead of starting at 0 you start at 1...so dates 1-16 calculate trend. Note that we wont end at the same value.

I have some code below but I am gettign a lot of errors and I don't know how to account for the fact that we won't always end at the same date.

At the end of the loop I am to have a list of all possible trends collected (should be a VERY long list)

d1=ds2['time'].isel(time=0). #this is to select time variable in the data set DATA = ds['DATA'] #this is to select the data from the imported data set time_len=len(ds2['time']) num_mon=15*12 #so all the data points are in monthly incraments you want to account for that you want it for 15 years timeline=np.arange(0,15*12,1) #not sure if I need this. trends_collected=[] #list of trends i=0 while i <=21456: #this is the amount of months in the data. I looked at the length of the time and subtracted 15 years from it for tt in range(i,time_len-i,num_mon): time_data = ds['DATA'].isel(time=slice(tt,tt+num_mon)) slope, intercept, r_value, p_value, std_err = stats.linregress(timeline,time_data) #calculate a linear regression for data trends_collected.append(slope) i+=1

In the bold I get an error " all the input array dimensions except for the concatenation axis must match exactly "

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Define the term "Leasing"

Answered: 1 week ago

Question

What do you mean by Dividend ?

Answered: 1 week ago

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago

Question

Influences on Nonverbal Communication?

Answered: 1 week ago