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 3 years have passed since last update.

pandasのread_tableとread_csvの違い(初心者による初心者向けの説明)

Last updated at Posted at 2022-06-09

レコード形式のテキストファイルを読み込もうとしてread_csvを使ったらエラーが出た話

  • 24列からなるデータを読み込もうとしたら...
df = pd.read_csv('test.txt')

# エラーメッセージ
ParserError: Error tokenizing data. C error: Expected 1 fields in line 18, saw 3

原因

  • read_csvは引数を指定しなければ、","カンマ区切りのファイルしか受け付けない。
  • このテキストファイルの場合は区切り文字が”\t”(タブ文字)だった。

解決法

  • read_csvの代わりにread_tableを使えばよい。read_tableはデフォルトで区切り文字が"\t"(タブ文字)になっているので、このファイルを扱うのに適している。

大事な知識

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?