代码解读
data=pd.read_csv('datingTestSet2.txt',sep='\t')
print(data.shape)
data.head()
飞行里程 视频游戏消耗时间 消费冰淇淋公斤数 感兴趣程度
0 40920 8.326976 0.953952 3
1 14488 7.153469 1.673904 2
2 26052 1.441871 0.805124 1
3 75136 13.147394 0.428964 1
4 38344 1.669788 0.134296 1
group=data.感兴趣程度.unique()
def group():
df=[]
group=data.感兴趣程度.unique()
for x in group:
a=data.飞行里程[data.感兴趣程度==x]
df.append(a)
return df
box1,box2,box3=group()[0],group()[1],group()[2]
我有点不明白group()函数是怎么执行的,麻烦大家帮忙解释下group()函数里的几句话是什么意思。执行完后,怎么自动分好组了。我看了group=data.感兴趣程度.unique()执行完后group={3,2,1},就是想不明白for循环。
推荐文章: