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?

【Python】pandasのread_csvメソッド

Last updated at Posted at 2025-06-22

read_csvメソッドは多数の引数が用意されています。例えば引数「header」でカラム名として使う行番号を指定したり、引数「index_col」でインデックス名として使う列番号を指定することができます。

次のCSVファイルで、先頭行をカラム名に指定し、先頭列をインデックス名に指定する場合を考えます。

sample.csv

,A列,B列,C列
1行,1,2,3
2行,4,5,6
3行,7,8,9

df = pd.read_csv('sample.csv')
▶︎
image.png

引数がない場合、先頭行がカラム名になり、インデックス名は連番が付与されます。引数で「header=None」とすると、カラム名も連番が付与されます。

df = pd.read_csv('sample.csv', index_col=0)
▶︎
image.png

引数「index_col=0」で、先頭列をインデックス名にするよう指定しています。

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?