Python Forum

Full Version: How to display sentence only from the database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I get the data from the database and I want to display sentence only. But, just display id and also sentence in one column. Example table output that I got:

{'id': '1', 'q': '- Happy'}

Example table output that I want to display:


I want to remove id ('id': '1')and just display word, in this case(Happy)

My code in
def programs(id):
    # Create cursor
    cur = mysql.connection.cursor()

    # Get articles
    result = cur.execute("SELECT id,y FROM table WHERE id = %s", [id])

    data = cur.fetchall()

    values = []

    for i in data:

        sid_obj = SentimentIntensityAnalyzer() 
        sentiment_dict = sid_obj.polarity_scores(i) 
        if sentiment_dict['compound'] >= 0.05 : 
            sentiment = 'positive'
        elif sentiment_dict['compound'] <= - 0.05 : 
            sentiment = 'negative'
        else : 
            sentiment = 'neutral'

        values.append({"y": i, "sentiment": sentiment, "sentiment_dict": sentiment_dict})

    if result > 0:
        return render_template('programs.html', data=values)
        msg = 'No Results Found'
        return render_template('programs.html', msg=msg)
Code in html:
{% for j in data%}
    {% endfor %}