以鸢尾花数据集为例
创造环境
import pandas as pd
from pandas.plotting import parallel_coordinates
import numpy as np
import matplotlib.pyplot as plt
引入数据,此时为dataframe
names = [‘sepal-length’, ‘sepal-width’, ‘petal-length’, ‘petal-width’, ‘class’]
iris = pd.read_csv(url, names=names)
从dataframe中提取数据,并将其作为散点图
d1=iris[‘sepal-length’]#直接后面中括号,里面是列标签名字即可
d2=iris[‘sepal-width’]
plt.scatter(d1[:50], d2[:50], color=’red’,
marker=’o’, label=’setosa’) #前50个样本
plt.scatter(d1[50:100], d2[50:100],
color=’blue’, marker=’x’, label=’versicolor’) #中间50个
plt.scatter(d1[100:], d2[100:],
color=’green’, marker=’+’, label=’Virginica’) #后50个样本
plt.legend(loc=2) #左上角标签
plt.show()
Original: https://blog.csdn.net/finance_farmer/article/details/120546814
Author: finance_farmer
Title: 从dataframe中提取一列,并作散点图
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/752226/
转载文章受原作者版权保护。转载请注明原作者出处!