I am looking for an option to generate a document in excel format, with information from a MongoDB database using the panda module, but until now I do not get it, it only generates the empty document and gives an error
Code that I use:
import sys
from pymongo import MongoClient
from pprint import pprint
import pandas as pd
client = MongoClient('localhost:27017')
db=client.equipos
def highlight_cells():
return ['background-color: red']
def multiple_dfs(df_list, sheets, file_name):
writer = pd.ExcelWriter(file_name,engine='xlsxwriter')
row = 0
for dataframe in df_list:
if dataframe.shape[1] == 1:
spaces = 0
print 'yes'
dataframe.style.apply(highlight_cells)
else:
spaces = 1
dataframe.to_excel(writer,sheet_name=sheets,startrow=row, startcol=0,index=False)
row = row + len(dataframe.index) + spaces + 1
writer.save()
collection = db.pond
title = "Title Test"
data = list(collection.find( { "time" : { "$gt" :1522897200 }, "time" : { "$lt" :1522897204 } }, {"idSonometro":1, "time" :1} ))
multiple_dfs([
pd.DataFrame({u'Document':[]}), title,
pd.DataFrame({u'Data':[]}),data], 'Info', 'example.xls')
The following is an error that generates: