Creating a Register Program with Pandas and Python

Asked

Viewed 84 times

-3

I’m creating an expense control to be used as a data science study. This is my expression:

def cadastro():
    
    descritivo = []
    valor = []
    condicao = []
    
    mes = input('Qual o mês vigente: ')[0:3].upper()
    quantidade = int(input('Quantas compras deseja registrar? '))
    

    for i in range(quantidade):
        dia = input("Qual o dia da sua compra: ")
        des = input('O que você comprou? ').upper()
        val = float(input('Qual o valor da compra: '))
        cond = input('Qual o método de pagamento? ').upper()
        descritivo.append(des)
        valor.append(val)
        condicao.append(cond)
        data = (f'2021/{mes}/{dia}')
        
  
        
        base = { 'Data': data,
                "Descritivo": descritivo,
                "Valor": valor,
                "Condição": condicao}
        
        dados = pd.DataFrame(data=base)
        
        
           
    return dados

cadastro()

The way it is, the date will always be unique to all other values. I would like to know how to add a new date, in this format 2021/Feb/01 and from the date, register as many products as I want.

as I ask the user to fill this with input?

  • Do not place compliments or thanks in questions or answers: Ref:https://answall.com/help/behavior

1 answer

0

Hi, if you append the date like you did with the other data, it will work as you expected:

descritivo = []
valor = []
condicao = []

data = []

and then:

descritivo.append(des)
valor.append(val)
condicao.append(cond)

data.append(f'2021/{mes}/{dia}')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.