1
2

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.

Pandasで読み込むデータの在り処を指定する

Posted at

ファイルを読み込む

参考
https://note.nkmk.me/python-pandas-read-csv-tsv/

tsvファイルを読み込む

tsvファイルとは、csvがコンマで区切られているのに対して、タブ(空欄)で区切られているファイル形式のこと。
read_csvで、区切り文字にタブ文字\tを設定する。

df= pd.read_csv('data/src/sample_header_index.tsv', index_col=0, sep='\t')

データの在り処を指定して読み込む

FileNotFoundErrorが出た場合は、データの在り処が間違っているかもしれない。
https://qiita.com/Oz-Spade/items/7fa479fae7a0ea6fcddf
https://qiita.com/redAlgae/items/1d9788b6f0b6613bf711

osモジュールを使って、ファイルが存在するディレクトリに移動してみる

import os
//今いるディレクトリの確認
os.getcwd() 
//ディレクトリの移動
os.chdir("/Users/W5966QZH/desktop")

あとはread_csvを使用してファイルを読み込む

df=read_csv('ファイル名')
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?