[Tutor] export pandas excel
Lucas Mascia
lucasmascia at gmail.com
Wed Oct 28 11:26:56 EDT 2015
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"]
> for name in ps_sol:
> ....
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.
-------------- next part --------------
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)
More information about the Tutor
mailing list