LoginSignup
0

More than 3 years have passed since last update.

pandas データの確認あれこれ2

Posted at

必要なデータを抽出

特定の列を3種類の異なる方法で抽出する。

df.iloc[:,1] # カラムのindexで指定可能
df.sepal_width # カラム名でも指定が出来る
df.loc[:,"retu_mei"] # 行を指定した後じゃないと使えない

50番目から99番目までのデータを抽出する

df[50:100]

petal_lengthの列の50番目から99番目までのデータを抽出する

df.iloc[:,3][50:100]

petal_widthの値が0.2のデータを抽出する

df[df['petal_width'].isin([0.2])]

.locや.ilocを使うことになります。この2つはどう違うのかについて説明しましょう!!

.loc:列名で指定可能で列のスライスが可能になる。
.iloc:列番号も指定する事が出来る。

めでたしめでたし。( ;∀;)

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