Discussion:
[Tutor] export pandas excel
Lucas Mascia
2015-10-28 15:26:56 UTC
Permalink
Hello,

Attached is my program, I have filtered some data from an extensive table
from excel. I have it running for two names:

ps_sol = ["Mauro Cavalheiro Junior", "Aline Oliveira"]
....
At the end I am trying to export to another .xlsx file. But it is only
saving the info of the last name in the list.

I want it to save for all names that i list in my ps_sol


Help please (:




| VIEW MY | <http://br.linkedin.com/pub/lucas-mascia/61/93/8b>

"It is not the strongest of the species that survives, nor the most
intelligent that survives. It is the one that is most adaptable to change."
- Darwin.
Alan Gauld
2015-10-28 23:25:44 UTC
Permalink
Post by Lucas Mascia
Hello,
Attached is my program,
When its a short program(<100 lines say) just include it in the text.
Attachments often get rejected by email gateways, especially on
corporate firewalls or for mobile devices.

=================================
import pandas as pd
import sys


#file loc
R1 = input('Data do Relatório desejado (dd.mm) ---> ')
loc = r'C:\Users\lucas.mascia\Downloads\relatorio-{0}.xlsx'.format(R1)

######################################################################

#Solicitantes
ps_sol = ["Mauro Cavalheiro Junior", "Aline Oliveira"]


#Aplicando filtros
for name in ps_sol:

#opening file
df = pd.read_excel(loc)
dfps = df[[2,15,16,17]]

#apply filter
f1 = dfps[(dfps['Cliente']=="POSTAL SAUDE")
& (dfps['Nome do solicitante']==name)]

#print info
print ('''
=============================================================
Relatorio do dia: {}
Cliente: POSTAL SAUDE
Solicitante: {}
=============================================================
'''.format(R1, name))

print (f1)

f1.to_excel('C:/Users/lucas.mascia/Downloads/ps_sol.xlsx', sheet_name=name)

===============================
Post by Lucas Mascia
At the end I am trying to export to another .xlsx file. But it is only
saving the info of the last name in the list.
Pandas is outside the scope of this list so I don't know much about
it. But is it possible that to_excel() creates a new file each time?
Is there an append flag you can pass maybe?

Finally in the line starting f1=dfps...

Is that really supposed to be a bitwise AND (&) operation? It seems
unlikely given the two operands are both boolean values. It should
work but it looks wrong. I would expect a logical AND (and).

I can't comment on the rest because it is too pandas (and data )
specific to make any sense to me.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription option
Continue reading on narkive:
Loading...