Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

Executing SQL query together with python

I wrote this code to find the only respondents to a question in Survey.

table_name = 'Samples' 

QUERY = """
select x.* 
from Samples as x
where x.Respondent IN

    (
    select Respondent
    from Samples
    group by Respondent
    having count(distinct Samples) = 1
    )
"""

df = pd.read_sql_query(QUERY,conn)
df[Samples].value_counts()

How may I include the python Code

df = pd.read_sql_query(QUERY,conn)
df[Samples].value_counts()

in the SQL code to count the respondent and to get the same result?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...