簡體   English   中英

使用 python 以最快的方式從 postgresql 檢索數據

[英]Retrieve data from postgresql in fastest way using python

我有以下代碼:

list1=[]
flatList_val=['user1','user2','user3','user4',......]
for val in flatList_val:
    #count=flatList.count(val)
    query="select count(title) as count from Data where authors like '%"+val+"%'"
    luk=getValues("",query)
    list1.append({"id":val,"size":(luk['count'].values[0])*20})

我在 flatlist 中有很多元素。如何以最快的方式從 POSTgresql db 中檢索數據? 注意:getvalues function 只是使用 psycog2 進行數據檢索的 python 代碼。 我基本上是在尋找執行速度最快的查詢

我已經使用pandas dataframe實際解決了它。請在下面找到解決方案:我不是每次都查詢,而是查詢所有信息並存儲在dataframe


    query="select authors from Data"
    luk=getValues("",query)
    
            for val in flatList_val:
                
                count=luk.authors.str.count(val).sum()
                list1.append({"id":val,"size":count*30})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM