我有以下代码从mongoDB读取数据并将其转换为数据框。
from pymongo import MongoClient
import pandas as pd
from datetime import datetime
client = MongoClient('localhost',27017)
db = client.test_insert ## name of the database
collection = db.test_dataset ## name of the collection
def main():
db.test_dataset.insert(
{
"user_id" : "9",
"date" : datetime.now()
}
)
df = pd.DataFrame(list(db.test_dataset.find()))
print df
if __name__ == "__main__":
main()
但它在Spyder中运行得很好......我做错了什么?
请帮助..