雅虎的货币和交易所名称
Currency and Exchange Name from Yahoo
我对 pandas(以及一般的编码)很陌生,但我真的很喜欢从 Yahoo Finance 中提取股票数据。
我只是想知道是否有办法同时从雅虎提取股票上市交易所的名称(即 LSE、NYSE、AIM 等)以及股票上市的货币?
这是我到目前为止的代码(今晚下班回来后我会添加一些轴标签):
import pandas as pd
import sys
import matplotlib
import matplotlib.pyplot as plt
import pandas_datareader.data as web
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
print('Matplotlib version ' + matplotlib.__version__)
symbols_list = ['ORCL', 'AAPL', 'TSLA']
d = {}
for x in symbols_list:
d[x] = web.DataReader(x, "yahoo", '2012-12-01')
ticker = pd.Panel(d)
df1 = ticker.minor_xs('Adj Close')
print df1
fig = plt.figure()
fig.suptitle("Stock Prices", fontsize=36, fontweight='bold')
plt.plot(df1)
plt.legend(ticker, loc='best', shadow=True, fontsize=36)
plt.show()
我认为你可以read_csv
from link, filter columns and then concat
them to df
. Then you can use loc
进行映射:
import pandas as pd
import sys
import matplotlib
import matplotlib.pyplot as plt
import pandas_datareader.data as web
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
print('Matplotlib version ' + matplotlib.__version__)
df_NASDAQ = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download',
usecols=['Symbol', 'Name'])
#print (df_NASDAQ.head())
df_NYSE = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download',
usecols=['Symbol', 'Name'])
#print (df_NYSE.head())
df_AMEX = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download',
usecols=['Symbol', 'Name'])
#print (df_AMEX.head())
df = pd.concat([df_NASDAQ, df_NYSE, df_AMEX]).set_index('Symbol')
print (df.head())
Name
Symbol
TFSC 1347 Capital Corp.
TFSCR 1347 Capital Corp.
TFSCU 1347 Capital Corp.
TFSCW 1347 Capital Corp.
PIH 1347 Property Insurance Holdings, Inc.
symbols_list = ['ORCL', 'AAPL', 'TSLA']
d = {}
for x in symbols_list:
print (x, df.loc[x, 'Name'])
ORCL Oracle Corporation
AAPL Apple Inc.
TSLA Tesla Motors, Inc.
#d[ x ] = web.DataReader(x, "yahoo", '2012-12-01')
d[ df.loc[x, 'Name'] ] = web.DataReader(x, "yahoo", '2012-12-01')
ticker = pd.Panel(d)
df1 = ticker.minor_xs('Adj Close')
print (df1.head())
fig = plt.figure()
fig.suptitle("Stock Prices", fontsize=36, fontweight='bold')
plt.plot(df1)
plt.legend(ticker, loc='best', shadow=True, fontsize=36)
plt.show()
我对 pandas(以及一般的编码)很陌生,但我真的很喜欢从 Yahoo Finance 中提取股票数据。
我只是想知道是否有办法同时从雅虎提取股票上市交易所的名称(即 LSE、NYSE、AIM 等)以及股票上市的货币?
这是我到目前为止的代码(今晚下班回来后我会添加一些轴标签):
import pandas as pd
import sys
import matplotlib
import matplotlib.pyplot as plt
import pandas_datareader.data as web
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
print('Matplotlib version ' + matplotlib.__version__)
symbols_list = ['ORCL', 'AAPL', 'TSLA']
d = {}
for x in symbols_list:
d[x] = web.DataReader(x, "yahoo", '2012-12-01')
ticker = pd.Panel(d)
df1 = ticker.minor_xs('Adj Close')
print df1
fig = plt.figure()
fig.suptitle("Stock Prices", fontsize=36, fontweight='bold')
plt.plot(df1)
plt.legend(ticker, loc='best', shadow=True, fontsize=36)
plt.show()
我认为你可以read_csv
from link, filter columns and then concat
them to df
. Then you can use loc
进行映射:
import pandas as pd
import sys
import matplotlib
import matplotlib.pyplot as plt
import pandas_datareader.data as web
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
print('Matplotlib version ' + matplotlib.__version__)
df_NASDAQ = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download',
usecols=['Symbol', 'Name'])
#print (df_NASDAQ.head())
df_NYSE = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download',
usecols=['Symbol', 'Name'])
#print (df_NYSE.head())
df_AMEX = pd.read_csv('http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download',
usecols=['Symbol', 'Name'])
#print (df_AMEX.head())
df = pd.concat([df_NASDAQ, df_NYSE, df_AMEX]).set_index('Symbol')
print (df.head())
Name
Symbol
TFSC 1347 Capital Corp.
TFSCR 1347 Capital Corp.
TFSCU 1347 Capital Corp.
TFSCW 1347 Capital Corp.
PIH 1347 Property Insurance Holdings, Inc.
symbols_list = ['ORCL', 'AAPL', 'TSLA']
d = {}
for x in symbols_list:
print (x, df.loc[x, 'Name'])
ORCL Oracle Corporation
AAPL Apple Inc.
TSLA Tesla Motors, Inc.
#d[ x ] = web.DataReader(x, "yahoo", '2012-12-01')
d[ df.loc[x, 'Name'] ] = web.DataReader(x, "yahoo", '2012-12-01')
ticker = pd.Panel(d)
df1 = ticker.minor_xs('Adj Close')
print (df1.head())
fig = plt.figure()
fig.suptitle("Stock Prices", fontsize=36, fontweight='bold')
plt.plot(df1)
plt.legend(ticker, loc='best', shadow=True, fontsize=36)
plt.show()