Using python pandas dataframe (d) downloaded from yahoo finance which has the format:
Date,Open,High,Low,Close,Volume,Adj Close
2015-01-13,1.290,1.290,1.200,1.225,421600,1.225
I can successfully use talib functions like this:
talib.abstract.EMA(d, timeperiod=8, price='Close')
talib.abstract.SMA(d, timeperiod=13, price='Close')
talib.abstract.RSI(d, timeperiod=25, price='Close')
From the documentation (http://mrjbq7.github.io/ta-lib/func_groups/momentum_indicators.html) they take the form:
real = XYZ(close, timeperiod=14)
However when trying to use the talib functions with the form:
real = XYZ(high, low, close, timeperiod=14) such as the ADX I cant figure out the correct syntax needed.
I've tried this:
talib.abstract.ADX(d,high='High',low='Low',close='Close',Timeperiod=10)
Exception: input_arrays parameter missing required data keys: high, low, close
and this:
talib.abstract.ADX(high=d.High,low=d.Low,close=d.Close,Timeperiod=10)
TypeError: only length-1 arrays can be converted to Python scalars
Any ideas on the correct format for the parameters needed for this and the other talib python wrappers that have more than one input parameter ?
Any help on the correct format would be greatly appreciated !!!
Thanks in advance
Depends on the shape of your arrays in some cases. If you really need the function as a matter of urgency, just call it from the library:
import talib
import numpy as np
h = np.array(high)
l = np.array(low)
c = np.array(close)
output_atr = np.array(talib.ATR(h,l,c,14))
This works fine.
Related
I was using a CSV and took out a few dates then resaved it and suddenly my code that worked before did not work anymore. I tried referencing the old CSV and got the same error despite it running fine before.
Here is what I had tried:
import numpy as np
import pandas as pd
Q = pd.read_csv("Data_V3.csv")
Q['date'] = pd.to_datetime(Q['date'], format='%m-%d-%Y')
The CVS looks like this:
date: flow:
1/1/1930 1300
I also tried:
Q['date'] = pd.to_datetime(Q['date'], format='%Y-%m-%d')
The full error is: "ValueError: time data '1/1/1930' does not match format '%m-%d-%Y' (match)"
Thank you!
You need to use / instead of - in your code to match the format.
Q['date'] = pd.to_datetime(Q['date'], format='%m/%d/%Y')
When you read the error, it gives you some information you probably skip over when you read it:
"ValueError: time data '1/1/1930' does not match format '%m-%d-%Y' (match)"
That is an exact example of what broke your code. Then it gives you the format as well. The only difference that breaks it is a / from the example given.
Hey did you try to change you're .csv into :
date: flow:
01/01/1930 1300
So I have a bit of code in python which tries to get home prices from zillow. I am following the documentation exactly but I still get errors. The code:
import quandl
quandl.ApiConfig.api_key = "I have a key here in the code"
data = quandl.get("http://www.quandl.com/api/v3/datasets/ZILL/S00022_A.csv", returns="numpy")
This, however, returns:
raise ValueError(Message.ERROR_COLUMN_INDEX_TYPE % dataset)
ValueError: The column index must be expressed as an integer for http://www.quandl.com/api/v3/datasets/ZILL/S00022_A.csv.
What does this mean and how do I fix it? Thanks in advance.
The code quandl.get() goes with the installed csv file and not an URL. So please import a dataset code and try to import it in your code by
quandl.get('WIKI/GOOGL')
Here, I have imported a dataset for stock prediction of Google
I'm trying to use the pandas read_sas() function.
First, I create a SAS dataset by running this code in SAS:
libname tmp 'c:\temp';
data tmp.test;
do i=1 to 100;
x=rannor(0);
output;
end;
run;
Now, in IPython, I do this:
import numpy as np
import pandas as pd
%cd C:\temp
pd.read_sas('test.sas7bdat')
Pretty straightforward and seems like it should work. But I just get this error:
TypeError: read() takes at most 1 argument (2 given)
What am I missing here? I'm using pandas version 0.18.0.
According issue report linked below, this bug will be fixed in 18.1.
https://github.com/pydata/pandas/issues/12647
When using the feather package (http://blog.cloudera.com/blog/2016/03/feather-a-fast-on-disk-format-for-data-frames-for-r-and-python-powered-by-apache-arrow/) to try and write a simple 20x20 dataframe, I keep getting an error stating that strided data isn't yet supported. I don't believe my data is strided (or out of the ordinary), and I can replicate the sample code given on the website, but can't seem to get it to work with my own. Here is some sample code:
import feather
import numpy as np
import pandas as pd
tempArr = reshape(np.arange(400), (20,20))
df = pd.DataFrame(tempArr)
feather.write_dataframe(df, 'test.feather')
The last line returns the following error:
FeatherError: Invalid: no support for strided data yet
I am running this on Ubuntu 14.04. Am I perhaps misunderstanding something about how pandas dataframes are stored?
Please come to GitHub: https://github.com/wesm/feather/issues/97
Bug reports do not belong on StackOverflow
I am trying to read a file with complex numbers in the form :
data.dat
1.5795219122457646E-11-3.852906516379872E-15i -3.5949335665378405E-12-1.626143709108086E-15i
-6.720365121161621E-15-5.377186331212649E-17i -3.736251476362349E-15-3.0190920417856674E-17i
I use the following code to read the file :
import numpy as np
c_complex = np.loadtxt('data.dat', delimiter='\t', dtype=np.complex128)
But it gives me the following error :
TypeError: complex() argument must be a string or a number, not 'bytes'
What could I do to solve this problem ?
Thank you very much for your help
This seems to have been a bug in older versions of numpy (Issue). Either update your numpy to the latest version of their github repository or use the function numpy.genfromtxt().
c.complex = np.genfromtxt('data.dat', delimiter='\t', dtype=np.complex128)