0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

csv ファイルを読み込み表示する

Posted at

csv ファイルを読み込み1セルずつprintする

  1. import csv で csvライブラリを使用する。
  2. with open() で csvファイルを開いて、close忘れ防止。
  3. csv.reader() で reader を使って1行-1セルずつデータを取得してprintする。
import csv

# csv ファイルを読み取りで開く。
with open(r".\sample.csv", mode="r", encoding="UTF-8") as file:

    # csv reader を取得する。
    # (書式の指定は dialect でまとめて指定する。)
    reader = csv.reader(file, dialect=csv.excel_tab)

    # 1行ずつ取得する
    for row in reader:
        for cell in row:
            # 改行の変わりにタブを出力し、セル情報のみ出力する。
            print(cell, end='\t')

        # 改行
        print()
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?