Skip to content

Instantly share code, notes, and snippets.

@mindsdbadmin
Last active March 17, 2021 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindsdbadmin/08fb09e26f234f40027cdb01b11f9f08 to your computer and use it in GitHub Desktop.
Save mindsdbadmin/08fb09e26f234f40027cdb01b11f9f08 to your computer and use it in GitHub Desktop.
# Single query with join and group by
sql_str = """
SELECT
category,
avg(sentiment_polarity) as avg_sentiment_polarity,
avg(sentiment_subjectivity) as avg_sentiment_subjectivity
FROM (
SELECT
category,
CAST(sentiment as float) as sentiment,
CAST(sentiment_polarity as float) as sentiment_polarity
FROM gstore_apps_df
INNER JOIN gstore_reviews_df
ON gstore_apps_df.app = gstore_reviews_df.app
) sub
GROUP BY category
HAVING avg_sentiment_subjectivity < 0.5
ORDER BY avg_sentiment_polarity DESC
LIMIT 10
"""
# Run query using apps and reviews dataframes,
# NOTE: that you simply pass the names of the tables in the query as arguments
result_df = mdsql.query( sql_str,
gstore_apps_df = gstore_apps_df,
gstore_reviews_df = gstore_reviews_df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment