import pandas as pd
from pymongo import ASCENDING, UpdateOne, MongoClient
import traceback
from pymongo import UpdateOne, ASCENDING
from pymongo import MongoClient
# 筛选数据
client = MongoClient("localhost", 27017)
db = client["local"]
col = db["stock"]
data = pd.DataFrame(list(col.find()))
data["date"] = pd.to_datetime(data["date"])
data_2019 = data[(data["date"] >=pd.to_datetime("20190101")) & (data["date"] <= pd.to_datetime("20191231"))]
data_2019.columns = ["ID", "_id", "日期", "代码", "开盘","最高", "最低","收盘", "成交量","成交额"]
# 写入本地
data_2019.to_csv("D:/StockData/2019.csv",encoding="utf-8")