雅虎的货币和交换名称

时间:2016-06-01 07:27:46

标签: pandas currency yahoo yahoo-finance

我对熊猫(以及一般编码)很陌生,但我真的很喜欢从雅虎财经中提取股票数据。

我只是想知道是否还有一种方法可以拉出股票所在的交易所的名称(即伦敦证券交易所,纽约证券交易所,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()

1 个答案:

答案 0 :(得分:0)

我认为您可以fill read_csv来过滤列,然后link将它们转换为df。然后你可以使用concat进行maping:

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()