Answers for "python create a csv"

16

create csv file python

# This action requires the 'csv' module
import csv

# The basic usage is to first define the rows of the csv file:
row_list = [["SN", "Name", "Contribution"],
             [1, "Linus Torvalds", "Linux Kernel"],
             [2, "Tim Berners-Lee", "World Wide Web"],
             [3, "Guido van Rossum", "Python Programming"]]

# And then use the following to create the csv file:
with open('protagonist.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerows(row_list)
# This will create a csv file in the current directory
Posted by: Guest on February-24-2020
0

créer csv python

#!/usr/bin/env python
# -*-coding: utf-8 -*

entetes = [
     u'Colonne1',
     u'Colonne2',
     u'Colonne3',
     u'Colonne4',
     u'Colonne5'
]

valeurs = [
     [u'Valeur1', u'Valeur2', u'Valeur3', u'Valeur4', u'Valeur5'],
     [u'Valeur6', u'Valeur7', u'Valeur8', u'Valeur9', u'Valeur10'],
     [u'Valeur11', u'Valeur12', u'Valeur13', u'Valeur14', u'Valeur15']
]

f = open('monFichier.csv', 'w')
ligneEntete = ";".join(entetes) + "n"
f.write(ligneEntete)
for valeur in valeurs:
     ligne = ";".join(valeur) + "n"
     f.write(ligne)

f.close()
Posted by: Guest on August-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language