使用Python导出过滤的Excel表

时间:2015-10-28 15:35:15

标签: python excel csv export

Python 3.4.3 | Anaconda 2.3 |熊猫

我已从广泛的Excel中过滤了一些数据。我让它运行两个名字:

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)

最后,我正在尝试导出到另一个.xlsx文件。但它只保存列表中姓氏的信息。

我想要保存我在ps_sol中列出的所有名字

请帮助(:

0 个答案:

没有答案