历史行情好像下载到了DB文件, 现在想再弄成CSV, 到excel文件里先手工,有啥快捷的办法导出到csv吗?
历史行情好像下载到了DB文件, 现在想再弄成CSV, 到excel文件里先手工,有啥快捷的办法导出到csv吗?
用python的sqlite库,写个脚本30行左右吧
#!/usr/bin/env python
import json
import pandas as pd
from pprint import pprint
from datetime import datetime
from vnpy.trader.database import database_manager
from vnpy.trader.setting import get_settings
from vnpy.trader.constant import Exchange
setting = get_settings()
ticks = database_manager.load_tick_data(
'au2006',
Exchange.SHFE,
start = datetime(2000,1,1),
end = datetime(3000,1,1)
)
for tick in ticks:
tick.exchange = tick.exchange.value
ticks = [tick.__dict__ for tick in ticks]
df = pd.DataFrame(ticks)
df.to_csv('t.csv')
非常感谢
张加林 wrote:
#!/usr/bin/env python import json import pandas as pd from pprint import pprint from datetime import datetime from vnpy.trader.database import database_manager from vnpy.trader.setting import get_settings from vnpy.trader.constant import Exchange setting = get_settings() ticks = database_manager.load_tick_data( 'au2006', Exchange.SHFE, start = datetime(2000,1,1), end = datetime(3000,1,1) ) for tick in ticks: tick.exchange = tick.exchange.value ticks = [tick.__dict__ for tick in ticks] df = pd.DataFrame(ticks) df.to_csv('t.csv')