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

More than 5 years have passed since last update.

pandasでcsvファイルの下から数行を取り出す

Posted at

上から10行だと

data = pd.read_csv('file.csv', nrows=10)

で取り出せる。

下から10行だと少し大変。

#最終行を取得する
lastRow = sum(1 for line in open('file.csv')) - 2
#最終行から10行の行数を求める。
pickRow = [lastRow - line for line in range(10)]
pickRow.reverse()
data = pd.read_csv('file.csv', skiprows=lambda x: x not in pickRows)
1
0
2

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
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?