Search code examples
pythonpandasdataframesyntax-error

pandas to_csv is creating csv with sep = "|", but the read_csv only works with sep = ","


I am working with a dataframe (testeEstadosSeparados) and when I want to save it as a csv file using "|" (or even ";") separator I am able to save the file but when I will read it, it just open when I set the regular comma as sep.

    testeEstadosSeparados.to_csv("/home/ec2-user/SageMaker/Bases/infraEscola-UF-semDuplicacoes/planosDeAcao_Escolas_{}.csv".format(pegaNomeDoCampo_Contagem(paths[0]),                                    index = False, sep = "|", encoding="utf-8"))

If I try to read as bellow it generate a error.

    pd.read_csv("/home/ec2-user/SageMaker/Bases/infraEscola-UF-semDuplicacoes/planosDeAcao_Escolas_MG.csv", sep="|", encoding="utf-8")

Error:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 80, saw 2


Solution

  • It was a noob problem.. I forgot to close a ")" in my function..