1

I have a dataframe as below. I would like to apply a function I have defined ( hurst() ) to each column (it takes a time series as an argument) and then output the results to another data frame.

def hurst(ts):
    #returns the Hurst Exponent of the time series vector ts

    # Create the range of lag values
    lags = range (1,5)

    # Calculate the array of the variances of the lagged differences
    tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]

    # Use a linear fit to estimate the Hurst Exponent
    poly = polyfit(log(lags), log(tau), 1)

    # Return the Hurst exponent from the polyfit output

    return poly[0]*2.0

How do I get from this

enter image description here

to

enter image description here

The full data frame has a 1y Dt history and continues E, F etc

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
S.Peters
  • 185
  • 1
  • 1
  • 9
  • What's wrong with `df.sum()`? it would help to accurately define your problem as this simplified example already has an answer – EdChum Apr 11 '17 at 15:54
  • Yes. Look at `apply` df.apply(yourFunction) either column-wise or row-wise (not recommended). – Scott Boston Apr 11 '17 at 15:56
  • my function is below, but using df.apply(hurst,axis=1) I get a You cannot change part of an array error. def hurst(ts): #returns the Hurst Exponent of the time series vector ts # Create the range of lag values lags = range (2,50) # Calculate the array of the variances of the lagged differences tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags] # Use a linear fit to estimate the Hurst Exponent poly = polyfit(log(lags), log(tau), 1) # Return the Hurst exponent from the polyfit output return poly[0]*2.0 – S.Peters Apr 11 '17 at 16:32
  • @S.Peters please add your code to the question and make sure that you have a [MWE](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Jan Trienes Apr 11 '17 at 16:37

0 Answers0