LoginSignup
0
0

More than 1 year has passed since last update.

locについて

Posted at

locは行と列のラベルを指定

DataFrameオブジェクト.loc['行ラベル’,'列ラベル’]

例をいくつか挙げる。
コロナウイルスへの4つの試験薬がある。その試験薬を用いるときに陽性、陰性をそれぞれダミー変数とし、陽性を1,陰性を0とおく。

②試験薬(T1,T2,T3,T4)と結果(陰性陽性)

T1=[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]
T2=[0,0,1,1,0,1,0,1,1,0,1,1,0,0,1,0]
T3=[1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,1]
T4=[1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0]
r=[1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0]

data2={'T1':T1,'T2':T2,'T3':T3,'T4':T4,'result':r}

df2=DataFrame(data2)
df2

T1	T2	T3	T4	result

0 1 0 1 1 1
1 1 0 1 1 1
2 1 1 1 1 1
3 1 1 1 0 0
4 1 0 1 0 0
5 1 1 0 1 0
6 1 0 0 1 0
7 1 1 0 1 0
8 0 1 0 1 1
9 0 0 1 1 1
10 0 1 0 1 1
11 0 1 0 1 1
12 0 0 0 1 1
13 0 0 1 0 0
14 0 1 0 0 0
15 0 0 1 0 0


X=df2.loc[:,'T1':'T4'].values # DataFrameオブジェクト.loc['行ラベル’,'列ラベル’]
Y=df2['result'].values #DataFrameオブジェクト.loc['行ラベル’,'列ラベル’]

Xの場合
行ラベル、つまり、今回でいうと0~15
列ラベル、つまり、T1~T4までを選択している。注意 ’T1’:'T2':'T3':'T4'←これは誤り(:の記号は~の意味を表すので誤り)

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