[PYTHON] Pandas reverse lookup memo

I will put together things that I will use again later (Note: Please note that there is nothing new about the content of the personal memo article)

Introduction

Data set preparation

import pandas as pd
from sklearn import datasets
iris = datasets.load_iris()
columns = list(map(lambda x: ' '.join(x.split(' ')[:2]), iris.feature_names))
df = pd.DataFrame(iris.data, columns=columns)
df['target'] = iris.target_names[iris.target]
df.head()

スクリーンショット 2019-12-28 16.17.56.png

View the number of data per label

Overview

df.groupby('target').size().to_frame.plot.barh()

Execution result: スクリーンショット 2019-12-28 16.21.17.png

Commentary

See a color-coded scatter plot for each label

Overview

for key, indices in df.groupby('target').groups.items():
    x = df.loc[indices]['sepal length']
    y = df.loc[indices]['petal length']
    plt.scatter(x, y, label=key, alpha=0.4)
plt.legend()
plt.show()

Execution result: スクリーンショット 2019-12-28 17.30.48.png

Commentary

Recommended Posts

Pandas reverse lookup memo
Pandas memo
pandas memo
Django admin screen reverse lookup memo
Reverse lookup pytest
Luigi Reverse Lookup Reference
Server setting tips Reverse lookup
My reverse numpy / scipy memo
Visualization memo by pandas, seaborn
Reverse lookup Numpy / Pandas (will be updated at any time)
Pandas memo ~ None, np.nan, empty string ~
Pandas
[Memo] Small story of pandas, numpy
Python Date / Time Library Reverse Lookup Reference