我是python和postgresql的新手
我一直在与使用python硬编码每个json行进行斗争,我不认为这是可扩展的方法.如果有人可以指向我可以处理从python插入json而无需硬编码的文献或文档.
我调查了COPY.
假设我使用gsub并想从字符串中删除以下(=,+, - )符号并用下划线替换.
当我尝试使用带加号(+)的gsub时,有人可以描述发生了什么.
test<- "sandwich=bread-mustard+ketchup"
# [1] "sandwich=bread-mustard+ketchup"
test<-gsub("-","_",test)
# [1] "sandwich=bread_mustard+ketchup"
test<-gsub("=","_",test)
# [1] "sandwich_bread_mustard+ketchup"
test<-gsub("+","_",test)
#[1] "_s_a_n_d_w_i_c_h___b_r_e_a_d___m_u_s_t_a_r_d_+_k_e_t_c_h_u_p_"
Run Code Online (Sandbox Code Playgroud) 我从终端运行sparkR 2.0.0,我可以运行R命令.但是,如何创建.r脚本并能够在spark会话中运行它.
期望的输出是第一个非负列表的索引.
说我嵌套了下面的数字列表.我试图弄清楚如何删除否定列表的值或只返回列表中所有值为正的索引.
我的想法是枚举或循环一个函数,该函数检查列表是否具有负值,然后从列表列表中弹出或删除
或者我是否使用列表理解?
# pseudocode
x = [[-1, -2, -1], [-1, -3, -1], [1, 2, 2]]
index_x = [x.index(non_negative(x)) for x in data]
print(index_x)
# 2
Run Code Online (Sandbox Code Playgroud) python ×2
r ×2
apache-spark ×1
gsub ×1
json ×1
jsonb ×1
postgresql ×1
psycopg2 ×1
sparkr ×1
stringr ×1