本文整理汇总了Python中pandas.io.data.DataReader.drop方法的典型用法代码示例。如果您正苦于以下问题:Python DataReader.drop方法的具体用法?Python DataReader.drop怎么用?Python DataReader.drop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.data.DataReader
的用法示例。
在下文中一共展示了DataReader.drop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_ohlc
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import drop [as 别名]
def download_ohlc(sector_tickers, start, end):
sector_ohlc = {}
for sector, tickers in sector_tickers.iteritems():
print 'Downloading data from Yahoo for %s sector' % sector
data = DataReader(tickers, 'yahoo', start, end)
for item in ['Open', 'High', 'Low']:
data[item] = data[item] * data['Adj Close'] / data['Close']
data.rename(items={'Open': 'open', 'High': 'high', 'Low': 'low',
'Adj Close': 'close', 'Volume': 'volume'},
inplace=True)
data.drop(['Close'], inplace=True)
sector_ohlc[sector] = data
print 'Finished downloading data'
return sector_ohlc
示例2: Equity
# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import drop [as 别名]
class Equity(object):
"""
An Equity object provides an interface to Share Price Data for a specified Ticker Code.
It uses pandas (DataReader and DataFrame) and SQLite as a local data store.
Use importData() to update the SQLite data from Yahoo (adjusting as necessary) and use dataFrame() to get at the
adjusted data.
"""
def __init__(self, tickerCode):
"""
Constructor.
There isn't much to see here. It just makes a note of the Ticker Code.
:param tickerCode: Ticker Code.
"""
Logger.log(logging.DEBUG, "Log Object Creation", {"scope":__name__, "arguments":" ".join({tickerCode})})
self._tickerCode = tickerCode
def importData(self):
"""
Import (New) Data from Yahoo.
"""
start = self._getLatestDate()
end = self._getTodaysDate()
Logger.log(logging.INFO, "Loading Data", {"scope":__name__, "tickerCode":self._tickerCode, "start":str(start), "end":str(end)})
self._data = DataReader(self._tickerCode, "yahoo", start, end)
self._data['Code'] = self._tickerCode
for item in ['Open', 'High', 'Low']:
self._data[item] = self._data[item] * self._data['Adj Close'] / self._data['Close']
self._data.drop('Close', axis=1, inplace=True)
self._data.rename(columns={'Adj Close':'Close'}, inplace=True)
self._data['Volume'] = self._data['Volume'].astype(float)
connection = sqlite3.connect(pyswing.database.pySwingDatabase)
query = "insert or replace into Equities (Date, Open, High, Low, Volume, Close, Code) values (?,?,?,?,?,?,?)"
connection.executemany(query, self._data.to_records(index=True))
connection.commit()
connection.close()
def dataFrame(self):
connection = sqlite3.connect(pyswing.database.pySwingDatabase)
query = "select * from Equities where Code = '%s'" % (self._tickerCode)
equityData = read_sql_query(query, connection, 'Date')
connection.close()
return equityData
def _getLatestDate(self):
connection = sqlite3.connect(pyswing.database.pySwingDatabase)
query = "select max(Date) from Equities where Code = '%s'" % (self._tickerCode)
cursor = connection.cursor()
cursor.execute(query)
dateString = cursor.fetchone()[0]
connection.close()
date = pyswing.constants.pySwingStartDate
if dateString:
date = datetime.datetime.strptime(dateString, "%Y-%m-%d %H:%M:%S")
return date
def _getTodaysDate(self):
return datetime.datetime.now()