0
1

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 1 year has passed since last update.

【Python】二次元リストからcsvファイル作成・追記

Last updated at Posted at 2022-04-19

環境

  • Microsoft Windows 10.0.22000.613(21H2)
  • Windows PowerShell 5.1.22000.613
  • conda 4.12.0
  • Python 3.8.12.final.0
  • csv 1.0

コード

py
import csv

CSV_PATH = "パス"
li = [["A", "B"], ["C", "D", "E"]]

with open(CSV_PATH, mode="a", encoding="utf-8") as f:
    writer = csv.writer(f)
    writer.writerows(li)
csv
A,B
C,D,E

csvモジュールについて

writerow(list):一行用
writerows(list):複数行用

open関数について

open(file, mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

mode

r:読み取り用(デフォルト)
w:上書き用
a:追記用

詳細は公式ドキュメントを参照

0
1
1

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?