在最后一列添加新的列,列名为wine; 添加的数据为随机正态分布,1/5的数据为1,剩余数据为-1;
df['wine']=-1
ran1=random.sample(range(0,len(df)//5),len(df)//5)#随机产生行号
for i in ran1:
df['wine'][ran1[i]]=1 #这里难道不是对wine列 ran1[i]行赋值为1吗,
#我的结果为什么是前面全是1, 后面是-1啊
在最后一行之后添加一行,随机添加1/4的数据为1,剩余为-1;
df.loc[len(df)] = -1
ran2=random.sample(range(0,df.shape[1]//4),df.shape[1]//4)#随机产生列号
for i in ran2:
df[ran2[i]][df.shape[0]]=1#这里难道不是对最后一行,ran2[i]列赋值为1吗
你有没有用ajax试过
html中写 姓名:
js中写:
$(function () {
$.ajax({
type: "post",
url: "你后台返回json的页面地址",
dataType: "json",
data: {"operation":"getsiteroomname","bigcatid":bigcatid},//传递到后台页面的参数,没有就不要了
contentType: "application/x-www-form-urlencoded; charset=utf-8",
success: function(data) {
console.log(data);//将返回的值打印出来看看,然后你就知道怎么用了,可能如data.username
var xm=data.username;
$("#username").text(xm);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('系统错误,联系管理员');
}
});
}
html中写姓名:<span id="username"></span>
js中写:
$(function () {
$.ajax({
type: "post",
url: "你后台返回json的页面地址",
dataType: "json",
data: {"operation":"getsiteroomname","bigcatid":bigcatid},//传递到后台页面的参数,没有就不要了
contentType: "application/x-www-form-urlencoded; charset=utf-8",
success: function(data) {
console.log(data);//将返回的值打印出来看看,然后你就知道怎么用了,可能如data.username
var xm=data.username;
$("#username").text(xm);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('系统错误,联系管理员');
}
});
}
在页面上写个div,然后ajax向后台发送请求,返回json数据,然后用push,将值显示到div里面去
方法很多,ajax fetch等都可以,fetch的优势可为碾压ajax。
fetch(url).then(function(response){ return reponse.json }).then(function(data){console.log(data)//这个data就是json的数据,用dom操作
将data打印到对应的标签显示在显示出来});
$.ajax({
type: "post",
url:'路径',
dataType:'json',
success:function(data)--后台给你的json数据
{
$("#员工号").val(data.员工号)
}
})