LoginSignup
0
0

More than 1 year has passed since last update.

【Python】Iris(アヤメ)のデータをpandasのdf(DataFrame)で読み込む方法

Last updated at Posted at 2022-10-12

背景

  • 以前、scikit-learnのToy datasetsの紹介記事を書きました。
  • 今回は、Toy datasetsの中でもよく使用されるIris(アヤメ)のデータを例に、pandasのDataFrame(df)での読み込み方法を紹介します。

目標

  • scikit-learnのIrisデータをDataFrame(df)で読み込めるようになる。

Irisデータをdfで読み込む方法

Irisデータをdfで読み込む方法
import pandas as pd
from sklearn.datasets import load_iris

#Irisデータをsklearnから読み込み
iris = load_iris()

#辞書型に近い型でデータが入っているので必要箇所を指定してdataとcoloumsとしてdfで読み込み
df = pd.DataFrame(data = iris.data, columns = iris.feature_names)

print(df)

#出力
     sepal length (cm)  sepal width (cm)  petal length (cm)  petal width (cm)
0                  5.1               3.5                1.4               0.2
1                  4.9               3.0                1.4               0.2
2                  4.7               3.2                1.3               0.2
3                  4.6               3.1                1.5               0.2
4                  5.0               3.6                1.4               0.2
..                 ...               ...                ...               ...
145                6.7               3.0                5.2               2.3
146                6.3               2.5                5.0               1.9
147                6.5               3.0                5.2               2.0
148                6.2               3.4                5.4               2.3
149                5.9               3.0                5.1               1.8

[150 rows x 4 columns]

参考資料

個人ブログ

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