本文整理汇总了Python中pandas.io.data.DataReader.iterrows方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.iterrows方法的具体用法?Python DataReader.iterrows怎么用?Python DataReader.iterrows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.data.DataReader
的用法示例。
在下文中一共展示了DataReader.iterrows方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTimewindowStockPrice
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import iterrows [as 别名]
def getTimewindowStockPrice(ticker):
timewindowStockPrice = {}#key: year; value: weekly price
stockDF = DataReader(ticker, "google", "2009-01-01", datetime.today().date())
# print stockDF
for idx, row in stockDF.iterrows():
# print row[0], row['Close']
# print datetime.fromtimestamp(idx)
# print str(idx)
dt = dateutil.parser.parse(str(idx)).date()
year = dt.isocalendar()[0]
week = dt.isocalendar()[1]
price = row['Close']
print year, week, price
if year not in timewindowStockPrice:
timewindowStockPrice[year] = {}
if week not in timewindowStockPrice[year]:
timewindowStockPrice[year][week] = []
# print row['Close']
timewindowStockPrice[year][week].append(price)
#normalized weekly price
for year in timewindowStockPrice.keys():
for week in timewindowStockPrice[year].keys():
timewindowStockPrice[year][week] = scipy.mean(timewindowStockPrice[year][week])
# for year in timewindowStockPrice.keys():
# print timewindowStockPrice[year]
return timewindowStockPrice
示例2: refreshYahooDatabase
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import iterrows [as 别名]
def refreshYahooDatabase(db):
rs = yahoo.yahooRecordset(db)
ts = timeseries.timeseriesRecordset(db)
# step 1: get the yahoo index end date
idx = rs.select('*')
for i in idx:
try:
r = ts.getLastDate(i['id'])
start = r[0]['max_date']
data = pd.DataFrame()
if start != None:
start = start + dt.timedelta(days=1)
data = DataReader( str(i['key']), 'yahoo', start)
else:
data = DataReader( str(i['key']), 'yahoo')
# insert new data
add = []
for index, row in data.iterrows():
add.append((i['id'], index, row[i['field']]))
ts.insert(add)
except Exception as e:
print('error processing index ' + str(i['key'] \
+ '/' + str(i['field']) + '\n'))
示例3: Indicator1
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import iterrows [as 别名]
class Indicator1():
def __init__(self, indicator, stock_name, start_date, end_date, buy_value, sell_value):
if not isinstance(stock_name, str):
raise TypeError("Sorry. 'Stock Name' must be string")
self.stock = DataReader(stock_name, "yahoo", start_date, end_date)
self.stock['returnValue'] = 'NaN'
self.stock['returnValue'] = 'NaN'
high_array = []
for index, row in self.stock.iterrows():
high_array.append(row['High'])
high_nparray = numpy.asarray(high_array)
low_array = []
for index, row in self.stock.iterrows():
low_array.append(row['Low'])
low_nparray = numpy.asarray(low_array)
close_array = []
for index, row in self.stock.iterrows():
close_array.append(row['Close'])
close_nparray = numpy.asarray(close_array)
real = getattr(talib, indicator)(high_nparray, low_nparray, close_nparray, timeperiod=14)
self.stock['indicator'] = real
self.stock['indicator_trigger'] = "NaN"
count = 0
flag = False
for index, row in self.stock.iterrows():
if count < len(self.stock.index):
if float(row['indicator']) < buy_value and (not flag):
self.stock['indicator_trigger'][count] = "Buy"
flag = True
elif float(row['indicator']) > sell_value and flag:
self.stock['indicator_trigger'][count] = "Sell"
flag = False
count += 1