Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

csv python write

import csv

with open('names.csv', 'w') as csvfile:
    fieldnames = ['first_name', 'last_name']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

    writer.writeheader()
    writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
    writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
    writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
Comment

python writing to csv file

import csv  

header = ['name', 'area', 'country_code2', 'country_code3']
data = ['Afghanistan', 652090, 'AF', 'AFG']

with open('countries.csv', 'w', encoding='UTF8') as f:
    writer = csv.writer(f)

    # write the header
    writer.writerow(header)

    # write the data
    writer.writerow(data)
Comment

python write to file csv

import csv  

header = ['name', 'area', 'country_code2', 'country_code3']
data = ['Afghanistan', 652090, 'AF', 'AFG']

with open('countries.csv', 'w', encoding='UTF8') as f:
    writer = csv.writer(f)

    # write the header
    writer.writerow(header)

    # write the data
    writer.writerow(data)
Comment

PREVIOUS NEXT
Code Example
Python :: python - make a copy of a df 
Python :: python csv read header only 
Python :: how to make a window in tkinter 
Python :: libreoffice add line in table 
Python :: argparse list 
Python :: python mock function return value 
Python :: limpiar consola en python 
Python :: how to change canvas background color in python tkinter 
Python :: django.core.exceptions.ImproperlyConfigured 
Python :: proper tree in data structure 
Python :: python remove n random elements from a list 
Python :: python colorama example 
Python :: pandas groupby size column name 
Python :: merge multiple csv files 
Python :: pandas inner join on two columns 
Python :: blackjack in python 
Python :: python telegram bot send image 
Python :: pandas dataframe convert string to float 
Python :: python type hint for a string 
Python :: python webdriver open with chrome extension 
Python :: get stock data in python 
Python :: python relative path 
Python :: discord py get user by id 
Python :: pathlib current directory 
Python :: how to read multiple files in a loop in python 
Python :: if keyboard.is_pressed 
Python :: python ignore unicodedecodeerror 
Python :: encryption python 
Python :: python assers 
Python :: minimum-number-of-steps-to-reduce-number-to-1 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =