I’m a Python newb, I tried searching if there were other similar questions but it doesn’t seem that there are. I’m really hoping my question isn’t ridiculous, and why I didn’t find others.
I have .txt file with 500 stock symbols that I have to include in my code to create an event matrix. I’m wondering if there is a way that I can somehow import the symbols into my line of code without having to type each individual symbol out. I’m using Python out of terminal if that makes a difference.
Also Running on virtual machine on Ubuntu 12.04
The line of code looks like this.
Symbols = [“”]
also somewhat unrelated to original question an example code shows this.
print ‘‘name’‘ + “reading data”
Do the underlines represent something else and it just shows up like that in .py, it just seems it would run an error when trying it out.
Thank you.
This assumes your file is of the form
and so on. And your file is named
tickers.txt.To do it in
PandasdoThis will load the file into a dataframe.
To do it in
NumpydoThis will load the file into a numpy array.
The above solutions work, but it’s probably overkill for a simple task like what you’re doing. I’d use vanilla python for this task.