Presentation is loading. Please wait.

Presentation is loading. Please wait.

MongoDB and Python Analysis

Similar presentations


Presentation on theme: "MongoDB and Python Analysis"— Presentation transcript:

1 MongoDB and Python Analysis
Robert, Kevin, Simi

2 Dataset Selection For this assignment we chose the Young People Survey from kaggle.com Data includes a large amount of 1-5 responses to various questions and answers to questions regarding demographics.

3 Loading into Mongo $ mongoimport -d Assingment3 -c Youngpeepss --type csv --file /Users/robertbrasso/Python/responses.csv –headerline Mongo – enter shell Show dbs – list databases Use Assignment3 – use Assignment3 database Show collections – list collections Db.Youngpeeps.find() – show documents in collection

4 Connect Mongo to Python
import pymongo from pymongo import MongoClient client = MongoClient() #connects to local host over port (mongo default) db = client.Assignment3 collection = db.Youngpeepss

5 Mongo Queries in Python
#Average weight,age, and height of males and females and unreported demographicsbygenderpipeline = [ {"$group": {"_id": "$Gender", "weightaverage" : {"$avg": "$Weight"}, "ageaverage" :{"$avg": "$Age"}, "heightaverage”:{"$avg":"$Height"}}}] print(list(db.Youngpeepss.aggregate(demographicsbygenderpipeline))) OUTPUT: [{'_id': '', 'weightaverage': 64.2, 'ageaverage': 22.2, 'heightaverage': 172.0}, {'_id': 'male', 'weightaverage': , 'ageaverage': , 'heightaverage': }, {'_id': 'female', 'weightaverage': , 'ageaverage': , 'heightaverage': }]

6 Queries cont… #Average age of all survey responders agepipeline = [ {"$group": {"_id": "null", "avgage":{"$avg":"$Age"}}}] print(list(db.Youngpeepss.aggregate(agepipeline))) OUTPUT: [{'_id': 'null', 'avgage': }]

7 Phobia Survey PHOBIAS Flying: Not afraid at all Very afraid of (integer) Thunder, lightning: Not afraid at all Very afraid of (integer) Darkness: Not afraid at all Very afraid of (integer) Heights: Not afraid at all Very afraid of (integer) Spiders: Not afraid at all Very afraid of (integer) Snakes: Not afraid at all Very afraid of (integer) Rats, mice: Not afraid at all Very afraid of (integer) Ageing: Not afraid at all Very afraid of (integer) Dangerous dogs: Not afraid at all Very afraid of (integer) Public speaking: Not afraid at all Very afraid of (integer)

8 Phobia Query #Average response for Phobia survey questions by gender phobiaavgpipeline = [ {"$group": {"_id": "$Gender", "Ageing" :{"$avg": "$Ageing"}, "Dangerous Dogs" :{"$avg": "$Dangerous dogs"}, "Darkness" :{"$avg": "$Darkness"}, "Flying" :{"$avg": "$Flying"}, "Heights" :{"$avg": "$Heights"}, "Public Speaking" :{"$avg": "$Fear of public speaking"}, "Rats" :{"$avg": "$Rats"}, "Snakes" :{"$avg": "$Snakes"}, "Spiders" :{"$avg": "$Spiders"}, "Storms" :{"$avg": "$Storm"} }}] print(list(db.Youngpeepss.aggregate(phobiaavgpipeline)))

9 Phobia results OUTPUT:
[{'_id': '', 'Ageing': , 'Dangerous Dogs': , 'Darkness': , 'Flying': , 'Heights': , 'Public Speaking': 3.5, 'Rats': 2.0, 'Snakes': , 'Spiders': 3.0, 'Storms': }, {'_id': 'male', 'Ageing': , 'Dangerous Dogs': , 'Darkness': , 'Flying': , 'Heights': , 'Public Speaking': , 'Rats': , 'Snakes': , 'Spiders': , 'Storms': }, {'_id': 'female', 'Ageing': , 'Dangerous Dogs': , 'Darkness': , 'Flying': , 'Heights': , 'Public Speaking': , 'Rats': , 'Snakes': , 'Spiders': , 'Storms': }]

10 Visualizations – Stacked Bar Chart

11 Visualizations – Scatter Plot

12 Visualization – Normalized Pivot Bar Chart

13 Visualizations – Linear Regression
r-squared: p value: e-88

14 Visualizations – Linear Regression
r-squared: p value: e-15

15 Visualizations – Linear Regression
r-squared: p value: e-66


Download ppt "MongoDB and Python Analysis"

Similar presentations


Ads by Google