本文整理汇总了Python中pandas.io.data.DataReader.save方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.save方法的具体用法?Python DataReader.save怎么用?Python DataReader.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.data.DataReader
的用法示例。
在下文中一共展示了DataReader.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import save [as 别名]
def load(symbol, startDate="19910428", forceDownload=False):
symbol = symbol.lower()
startDate = datetools.to_datetime(startDate) + datetools.bday - datetools.bday
dataPath = "data_from_yhoo"
# first check if data is in directory, or if there is even a directory
if not os.path.exists(dataPath):
print "data path doesn't exist. creating."
os.makedirs(dataPath)
# check if file is even there
# get all stock symbols by reading csv names from data folder
symbols = []
os.chdir(dataPath + "/")
for afile in glob.glob("*.df"):
symbols.append(afile[:-3]) # slice out csv extension
os.chdir("../") # reset dir
# if it is, read data. right now, if you don't download
if symbol in symbols and not forceDownload:
df = DataFrame.load(dataPath + "/" + symbol + ".df")
print "read " + symbol + " data from binary file"
df = df[df.index >= startDate]
return df
else:
# otherwise, redownload data from yahoo
print symbol + " data not downloaded. downloading from yhoo now..."
df = DataReader(symbol, "yahoo", startDate)
# save locally
df.save(dataPath + "/" + symbol + ".df")
# return data df
return df