我正在與大熊貓和SQLAlchemy將雅虎財務價格寫入SQL庫。我的問題是,如何從數據庫中刪除時間戳?pandas df.to_sql()刪除時間戳
全碼
def update (symbol):
engine = create_engine("sqlite:///test.db") # Access the DB Engine
try:
if not engine.dialect.has_table(engine, symbol): # If table does not exist. Create
start = dt.date(2000, 1, 1)
end = dt.datetime.today()
get_prices = yahoo.DataReader(symbol, 'yahoo', start, end)
get_prices.to_sql(symbol, engine, if_exists='append')
此代碼的工作,它得到的價格進入一個SQL數據庫。但日期部分出現像這樣2001-01-17 00:00:00.000000
。
我應該如何編輯我的代碼,使時間戳不顯示?
請發表您的完整信息源,請問? – hd1
你使用哪個數據庫? – van
默認情況下,索引('Date')的類型是'datetime64 [ns]'。爲了將它轉換爲'date',你可以在調用'get_prices.to_sql'之前執行'get_prices.index = get_prices.index.date'。 – van