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

Pandasの基本的な使い方

Posted at

Pandasの基本的な使い方

毎回調べなくても良いように、よく使いそうな機能のメモです

DataFrame

CSV読み込み

read_csv()メソッドを使う

import pandas as pd

df = pd.read_csv(file_path)

先頭から読み込む行を指定

引数nrows=行数で指定

10行読み込み

df = pd.read_csv(file_path, nrows=10)

先頭から読み込む時にSkipする行を指定

引数skiprows=行数で指定

2行Skip

df = pd.read_csv(file_path, skiprows=2)

列を指定して読み込み

usecols=xxxで指定する

index=0,1列目を指定したい場合

df = pd.read_csv(file_path,j usecol=[0,1])

index=0,1列目を名前で指定したい場合

df = pd.read_csv(file_path,j usecol=['col_0' ,'col_1'])

ヘッダ無しであることを明示する

通常は先頭行がヘッダ行だと推測されます

df = pd.read_csv(file_path, header=None)

DataFrameの列を指定する

'col_1'列を指定

print(df['col_1'])

DataFrameの複数の列を指定する

'col_1, col_3'列を指定

print(df[['col_1', 'col_3']])

参考

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