How to change the CSV file field separator from ',' to ';'

Asked

Viewed 1,066 times

0

I am developing a utility to transform XLS and XLSX files to CSV, but I would like CSV files to come out with semicolon separator instead of comma, here is the code:

# -*- coding: iso-8859-1 -*-
import glob
import pandas as pd

excel_files = glob.glob('D:\Conversao de Dados\Central de 
Utilitarios\PROJETOS\XLS2CSV\excel\*.xlsx') # caminho dos arquivos excel

for excel in excel_files:
    out = excel.split('.')[0]+'.csv'
    df = pd.read_excel(excel) # converte apenas 1 folha por arquivo
    df.to_csv(out) 

Much of the code is not my own and I am not experienced in Python, if anyone can help me, I would be very grateful...

  • Please see the documentation of pandas.DataFrame.to_csv

  • a simple way to do this is to write at the beginning of the Sep file=;

  • being the ; the type of separator that you want, can be anything else example: Sep=|

  • 1

    Got it personal, thanks for the help... just put the Sep = ';' after the out on the last line df.to_csv(out, Sep=';')

No answers

Browser other questions tagged

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