Attach only one line to a CSV file with pandas

Asked

Viewed 33 times

0

I am making a login system using very basic csv tables, because it is not the purpose of the program.

def criar_conta(self, respostas):
  framelogin = pd.read_csv('C:\TCC\Aplicacao\Arquivos CSV\Login_temp.csv', encoding = '#ISO-8859-1')
login = list(framelogin["login"])
senha = list(framelogin["senha"])
respostas.append(login[0])
respostas.append(senha[0])
frameclientes = pd.read_csv('C:\TCC\Aplicacao\Arquivos CSV\Clientes.csv', encoding = '#ISO-8859-1')

my problem is this:

I need to include the contents of the list respostas on the last line of the CSV Clientes.csv (i don’t want to have to delete the old file and create a new one with the new line, I want the file to be opened and written in it) if possible I would like it to be using the pandas library.

1 answer

0

Hello, well let’s go by parts. I had a little trouble understanding your problem :)

whereas respostas is a list and that framelogin and frameclientes sane dataframes, where framelogin has data that cannot get lost, respostas are the new data and that they should be stored in frameclientes. We have:

import pandas as pd
...

def criar_conta(self, respostas):
    framelogin = pd.read_csv('C:\TCC\Aplicacao\Arquivos CSV\Login_temp.csv', encoding='#ISO-8859-1')
    # transformando a lista em um df para concatenar
    df_respostas = pd.DataFrame('login': respostas[0], 'senha': respostas[1])
    frameclientes = pd.concat([framelogin, respostas], ignore_index=True)
    frameclientes.to_csv('C:\TCC\Aplicacao\Arquivos CSV\Clientes.csv', encoding='#ISO-8859-1')

Browser other questions tagged

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