Ivan
Ivan

Reputation: 7746

How to extract a column

def hurst(ts):
    """Returns the Hurst Exponent of the time series vector ts"""

I read a csv file and parse the columns into parsed:

try:
    with open(file) as csvfile:                
        parsed = (
    (row['time'],
    float(row['bid']),
    int(row['bid_depth']),
    int(row['bid_depth_total']),
    float(row['offer']),
    int(row['offer_depth']),
    int(row['offer_depth_total']))    
    for row in reader)

I can print this fine:

for row in parsed:
    print(row)

But how do I pass say the entire column of floats row[bid] to the function hurst?

Upvotes: 1

Views: 58

Answers (1)

doptimusprime
doptimusprime

Reputation: 9395

You can use list comprehension

mylist = [x for x in [r['bid'] for r in parsed]]

Now pass mylist to your function.

Upvotes: 1

Related Questions