[Tutor] export pandas excel

Alan Gauld alan.gauld at btinternet.com
Wed Oct 28 19:25:44 EDT 2015


On 28/10/15 15:26, Lucas Mascia wrote:
> 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)

===============================


> 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




More information about the Tutor mailing list