Dataframe input

Asked

Viewed 30 times

-1

Good morning guys, I’m creating a expense control to be used as a data science study. However, I would like to make the user able to enter the values and feed this dataframe. The expression I have is this:

pd.Timestamp (ano = 2024, mês = 2, dia = 24, hora = 0)
dt1 = Timestamp ('2024-02-24 00:00:00')

js1 = {'Data': [dt1, dt1, dt1, dt1],
       'Descritivo': ['Recarregar online', 'Cookie', 'Lunch', 'Pastel'],
        'Valor': [25,00, 2,90, 18,90, 12,0],
        'Condição': ['Crédito', 'Dinheiro', 'Bilhete', 'Nubank']}
d1 = pd.DataFrame (dados = js1)

as I ask the user to fill this with input?

1 answer

0

The input() function allows entering data. Creating a CSV file is possible to read with Pandas.

import csv
from datetime import datetime

ano = int(input("Ano: "))
mes = int(input("Mês: "))
dia = int(input("Dia: "))
hora = int(input("Hora: "))
descritivo = input("Descritivo: ")
valor = int(input("Valor: "))
condicao = input("Condição: ")

dt1 = datetime(ano, mes, dia, hora)

f = open('dados.csv', 'w')
writer = csv.writer(f)
writer.writerow([dt1, descritivo, valor, condicao])
f.close()

Browser other questions tagged

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