Having downloaded data from yahoo for a stock using the get_data_yahoo I then want to access the time for each row... How do I do that?
One way I've kind of figured out to do this is:
it = stock.iterrows()
st0 = it.next()
resultIWant = st0[0].value # this gives what I want (almost)
print resultIWant
EDIT:
So basically I want something like stock['Open'] but for time, smth like stock['Time'] would be ideal..
some one asked for the output of .head
Open High Low Close Volume Adj Close
Date
2012-04-03 2.06 2.09 2.01 2.08 463200 2.08
2012-04-04 2.04 2.05 2.01 2.02 335600 2.02
Expected output from function:
print find_time(stock,2) # function I'm looking for
1333497600000000000 # resulting output
The expected output is the time from the last epoch for each of the dates in an array or some other way to get the time of each entry. The example code I gave gives me the results I want however if I want to get access to the 4th element the only way to do it would be to .next the iterator 4 times, this seems like a bad method.
First Question: Is there a more obvious way, what I'm doing doesn't seem like the best way to do this.
Second Question: What units is the result in? I think it's nanoseconds but not sure...
Timestamps have a time method:
In [1]: t = pd.Timestamp('200101011300')
In [2]: t
Out[2]: <Timestamp: 2001-01-01 13:00:00>
In [3]: t.time()
Out[3]: datetime.time(13, 0)
The value is nanoseconds since midnight 1 January 1970 i.e. unix time * 10 ** 9:
In [4]: t.value
Out[4]: 978354000000000000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With