本文整理汇总了Python中pandas.io.data.DataReader.join方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.join方法的具体用法?Python DataReader.join怎么用?Python DataReader.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.data.DataReader
的用法示例。
在下文中一共展示了DataReader.join方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_data
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import join [as 别名]
def save_data():
start = '1/1/1990'
# Get S&P 500 data from yahoo
sp500 = get_data_yahoo('^GSPC', start=start)['Adj Close']
sp500.name = 'SP500'
vix = get_data_yahoo('^VIX', start=start)['Adj Close']
vix.name = 'VIX'
# Get ten year and 3 month t-bill rates
ten_yr = DataReader('DGS10', 'fred', start=start)
three_mon = DataReader('DGS3MO', 'fred', start=start)
ten_yr = ten_yr.ix[ten_yr.DGS10.str.count(r'^\.') != 1].astype(float)
three_mon = three_mon.ix[three_mon.DGS3MO.str.count(r'^\.') != 1].astype(float)
data = ten_yr.join(three_mon)
data = data.join(sp500)
data = data.join(vix)
# Drop non-like observations (obs on different days)
data = data.dropna()
data.save('SP_YC.db')
data.to_csv('the_data.csv')
示例2: only_alphanum
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import join [as 别名]
import pandas as pd
#
from pandas.io.data import DataReader
def only_alphanum(s):
#s = unicode(s, "utf-8")
return ' '.join(c for c in s.split() if c.isalnum())
def only_alpha(s):
return ' '.join(c for c in s.split() if c.isalpha())
def removeNonAscii(s): return "".join(i for i in s if ord(i)<128)
sp500 = DataReader("^GSPC", "yahoo", datetime(2009, 1, 1))
newsframe = pd.Series(news, name='News')
#descframe = pd.Series(descs, name='Desc')
frameWithNews = sp500.join(pd.DataFrame(newsframe))
#sp500Frame = frameWithNews.join(pd.DataFrame(descframe))
newsframe = pd.Series(news, name='News')
#descframe = pd.Series(descs, name='Desc')
frameWithNews = sp500.join(pd.DataFrame(newsframe))
newsReturns = frameWithNews['Adj Close'].pct_change()
newsReturns.name='Returns'
returnsFrame = frameWithNews.join(pd.DataFrame(newsReturns))
returnsFrame['UP'] = returnsFrame.Returns > 0.01
returnsFrame['DOWN'] = returnsFrame.Returns < -0.01
returnsFrame['NONE'] = (returnsFrame['UP']==False) & (returnsFrame['DOWN']==False)
droppedFrame = returnsFrame