46
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでcsvファイルに出力

Posted at

CSV形式で出力をしたい

スクレイプした情報をcsv形式で出力して、エクセルでごにょごにょしたい時とか

csv.py
# -*- coding: utf-8 -*-

import csv

# ファイルオープン
f = open('output.csv', 'w')
writer = csv.writer(f, lineterminator='\n')

# データをリストに保持
csvlist = []
csvlist.append("hoge")
csvlist.append("fuga")

# 出力
writer.writerow(csvlist)

# ファイルクローズ
f.close()

ちなみにファイルオープンの第二引数を a とすると追記モードになる

46
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?