Home » , » Ubah data csv ke excel dengan python

Ubah data csv ke excel dengan python

Written By SBlog on Monday, May 31, 2021 | May 31, 2021

Berikut ini kode python untuk merubah data csv menjadi excel.

import sys
import csv
from openpyxl import Workbook

csvfilename = 'output2.csv'
excelfilename = 'output2.xlsx'

wb = Workbook()
ws = wb.active

with open(csvfilename) as csv_file:
    csv_reader = csv.reader(csv_file, delimiter= ';') // Sesuaikan delimiter yang digunakan pada data csv
    for row in csv_reader:
        ws.append(row)
wb.save(excelfilename)

Jika belum ada library openpyxl

 $ pip install openpyxl

Data CSV

Hasil Data Excel



sumber: https://www.ashwoodcomputer.com/short-python-code-to-create-an-excel-file-from-a-csv-file/

0 comments:

Post a Comment

(^_^) [o_o] (^.^) (".") ($.$)