【发布时间】:2018-09-01 22:20:56
【问题描述】:
我正在从 excel 表中读取数据,需要将数据转储到 MongoDB。但是日期列作为数字插入,而不是 ISODate('')。我的代码是
df = pd.read_excel(excel_file, sheetname=0,index_col=None,converters={'Date': str})
df['Date'] = pd.to_datetime(df['Date'],format ="%Y-%m-%d %H:%M:%S")
df = pd.DataFrame.from_dict(df)
records = json.loads(df.T.to_json()).values()
print(records)
db = client.local
print(db)
evbal = db.test.insert_many(records)
输出:
{"Date":1519862400000,"AgentID": "xxxx", "LOB": "yy", "Channel":"os"}
【问题讨论】:
标签: python pandas dataframe jupyter-notebook python-3.5