我正在从 python 脚本运行一批 postgres 查询。部分查询如下:
create table xxx [...]
Run Code Online (Sandbox Code Playgroud)
通常我会收到以下错误:
psycopg2.ProgrammingError: relation "xxx" already exists
Run Code Online (Sandbox Code Playgroud)
我知道我可以手动删除xxx表,但是我问我是否有办法避免这个错误。类似删除 xxx 表(如果存在)之类的内容。
谢谢
对这个新手问题我很抱歉.我有一个数据框
l_tab$dis2_num$perc
Var1 dis pol dif
1 1 0.79867550 0.2198391 0.57883635
2 2 0.14569536 0.1983914 0.05269606
3 3 0.05562914 0.5817694 0.52614030
Run Code Online (Sandbox Code Playgroud)
我想在哪里找到dif的最小值.我试过这个:
> min(l_tab$dis2_num$perc["dif"])
>[1] 0.05269606
Run Code Online (Sandbox Code Playgroud)
这是正确的,但我想恢复行(在这种情况下2)
搜索这些东西,我试试这个:
推荐函数which.min().
当我尝试将此应用于我的数据时出现问题
> which.min(l_tab$dis2_num$perc["dif"])
Erreur dans which.min(l_tab$dis2_num$perc["dif"]) :
the objet (list) can't be converted to type 'double'
> typeof(l_tab$dis2_num$perc)
[1] "list"
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我的数据框已成为一个列表.
我也尝试过这个
> r = as.data.frame(r)
> r
Var1 dis pol dif
1 1 0.79867550 0.2198391 0.57883635
2 2 0.14569536 0.1983914 0.05269606
3 3 0.05562914 0.5817694 0.52614030
> typeof(r)
[1] …Run Code Online (Sandbox Code Playgroud) 我已经看到了这些解决方案:
但是,如果存在NA值,该方法将无法工作。
我尝试了这个:
s = append(sort(rexp(100)),rep(NA,30))
o = data.frame(s,s)
range01 <- function(x){
if (!is.na(x))
{
return(NA)
}
else{
y = (x-min(x))/(max(x)-min(x))
return(y)}
}
xo = apply(o,MARGIN = 2, FUN = range01)
Run Code Online (Sandbox Code Playgroud)
但这不起作用...建议吗?
该解决方案应通过apply函数在数据框上工作