我执行以下代码:
df<-data.frame(word=c("play","win","offer","http"),frequency=c(321,355,123,564),type=c("nonspam","nonspam","spam","spam"))
df=arrange(df,desc(frequency),desc(type))
df=df[order(df[,2],df[,3]),]
Run Code Online (Sandbox Code Playgroud)
结果是:
word frequency type
4 offer 123 spam
3 play 321 nonspam
2 win 355 nonspam
1 http 564 spam
Run Code Online (Sandbox Code Playgroud)
但我想根据频率和类型对数据框进行排序,例如:
word frequency type
1 http 564 spam
4 offer 123 spam
2 win 355 nonspam
3 play 321 nonspam
Run Code Online (Sandbox Code Playgroud) clist=[(-1.2720626442476508, 0.023952387163360456),
(1.509233613482305, -1.196551723413994),
(-0.37776845297034178, -1.9620288805522699),
(-0.95028695770255522, -1.5670871848691932),
(-0.19286972570683192, -1.2638500626369975),
(1.19847548993563, 0.32781113190011446),
(-0.93998357957640977, 0.74954973932266267),
(-0.65151553614971647, -0.65350263688351395),
(-0.65151553614971647, -0.65350263688351395)]
fig = plt.figure()
ax = plt.axes(xlim=(-2, 200), ylim=(-2, 2))
plt.plot(clist,'ro')
plt.show()
Run Code Online (Sandbox Code Playgroud)
如您所见,x坐标超过值2.y坐标是正确的.
c=np.random.rand(10,2)从中生成一个随机数组[0,1).我可以生成相同的数组(就大小而言)但是具有负数和正数吗?此外,我可以选择此阵列的限制和尺寸吗?例如,如果我想从-2到2.