散点图成K均值

时间:2020-01-31 11:10:13

标签: python pandas scikit-learn k-means scatter-plot

我有这段代码,可以执行以下操作:打开一个Csv文件,看起来像这样,但是只有更多行

enter image description here

这是代码

import pandas as pd
import os

df= pd.read_csv(r"C:/Users/z647818/Desktop/tree/tree.csv", delimiter=";", encoding='unicode_escape')
df['Numbers'] = df['Numbers'].str.split(',').str[0]
df['Numbers'] = df['Numbers'].astype('int64', copy=False)

def scatterGraph(str1):

    dfstr = df[df['Description'] == str1]
    dfstrval = df[df['Description'] == str1]['Numbers']
    print(dfstrval)
    dfstr.plot(kind='scatter', x='Numbers', y='Numbers')

str1 = 'Journey has started' # In order to search for any other string just put that string here.
scatterGraph(str1)

代码有什么作用? 转到“说明”列,按字符串名称Journey has started进行过滤,并绘制“数字”列中的所有值 结果看起来像这样。

enter image description here

我正在寻找一些帮助,以帮助您将相同的过滤结构转换为按列中的某个字符串,然后将值绘制为K均值

0 个答案:

没有答案