├── README.md ├── astros.json ├── astros_plot.png ├── death_plots.png ├── death_plots_causes.png ├── nchs_death_causes.csv └── project02.py /README.md: -------------------------------------------------------------------------------- 1 | # Project 2 2 | 3 | ## Fig 1: This graph shows the number of astronauts in space vs. the name of their craft. 4 | ![graph of number of astronauts in space vs. the name of their craft](https://github.com/dwalker25/project2/blob/main/astros_plot.png) 5 | 6 | Currently, there are 10 astronauts in space. 7 are in the ISS spacecraft and 3 are in the Tiangong space craft. This information is published by NASA for anyone who is curious. It is titled "How Many People are in Space Right Now". [Here](https://github.com/jdorfman/awesome-json-datasets) is where I found this [data](http://api.open-notify.org/astros.json). 7 | 8 | ## Fig 2: This graph shows the number of deaths in New York and North Dakota vs. time (1999-2017). 9 | ![graph of number of deaths in New York and North Dakota vs. time (1999-2017)](https://github.com/dwalker25/project2/blob/main/death_plots_causes.png) 10 | 11 | This data is published by the U.S. Department of Health & Human Services and can be found within a dataset that presents the age-adjusted death rates for the 10 leading causes of death in the United States beginning in 1999. I chose to look at New York and North Dakota because they are drastically different states. Beside the obvious difference in population size, it is interesting that the number of accidental deaths in New York has significantly increased in recent years. [Here](https://catalog.data.gov/dataset/nchs-leading-causes-of-death-united-states) is where I found this data. 12 | 13 | The [instructions](https://github.com/mikeizbicki/cmc-csci040/tree/2022fall/project_02) for this class project can be found here. 14 | -------------------------------------------------------------------------------- /astros.json: -------------------------------------------------------------------------------- 1 | {"message": "success", "people": [{"name": "Cai Xuzhe", "craft": "Tiangong"}, {"name": "Chen Dong", "craft": "Tiangong"}, {"name": "Liu Yang", "craft": "Tiangong"}, {"name": "Sergey Prokopyev", "craft": "ISS"}, {"name": "Dmitry Petelin", "craft": "ISS"}, {"name": "Frank Rubio", "craft": "ISS"}, {"name": "Nicole Mann", "craft": "ISS"}, {"name": "Josh Cassada", "craft": "ISS"}, {"name": "Koichi Wakata", "craft": "ISS"}, {"name": "Anna Kikina", "craft": "ISS"}], "number": 10} -------------------------------------------------------------------------------- /astros_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwalker25/project2/6ea51a90a0a8a09183559302ca781a516a2134c1/astros_plot.png -------------------------------------------------------------------------------- /death_plots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwalker25/project2/6ea51a90a0a8a09183559302ca781a516a2134c1/death_plots.png -------------------------------------------------------------------------------- /death_plots_causes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwalker25/project2/6ea51a90a0a8a09183559302ca781a516a2134c1/death_plots_causes.png -------------------------------------------------------------------------------- /project02.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # Opening JSON file 4 | f = open('astros.json') 5 | 6 | # returns JSON object as 7 | # a dictionary 8 | data = json.load(f) 9 | 10 | # Iterating through the json 11 | # list 12 | crafts = ['ISS', 'Tiangong'] 13 | counts = [] 14 | count_ISS = 0 15 | count_Tiangong = 0 16 | people = data['people'] 17 | for person in people: 18 | if person['craft'] == 'ISS': 19 | count_ISS += 1 20 | if person['craft'] == 'Tiangong': 21 | count_Tiangong += 1 22 | counts.append(count_ISS) 23 | counts.append(count_Tiangong) 24 | 25 | import numpy as np 26 | import matplotlib.pyplot as plt 27 | fig, ax = plt.subplots() 28 | ax.bar(crafts, counts) 29 | plt.title('# of Astronauts in Space vs. Craft') 30 | plt.xlabel('Crafts') 31 | plt.ylabel('# of Astronauts') 32 | plt.savefig('astros_plot.png') 33 | plt.show() 34 | #save direct to file 35 | 36 | import csv 37 | file = open('nchs_death_causes.csv') 38 | reader = csv.reader(file) 39 | xss = list(reader) 40 | ''' 41 | state_accumulator = [] 42 | count_accumulator_acc = [] 43 | count_accumulator_alz = [] 44 | for xs in xss: 45 | if xs[0] == '2017': 46 | if xs[1] == "Accidents (unintentional injuries) (V01-X59,Y85-Y86)": 47 | if xs[3][0] == 'A': 48 | state_accumulator.append(xs[3]) 49 | count_accumulator_acc.append(int(xs[4])) 50 | if xs[1] == "Alzheimer's disease": 51 | if xs[3][0] == 'A': 52 | count_accumulator_alz.append(int(xs[4])) 53 | ''' 54 | 55 | # # of accidental deaths in New York and North Dakota vs. time 56 | 57 | accum_year = [] 58 | accum_count_ny = [] 59 | accum_count_nd = [] 60 | for xs in xss: 61 | if xs[1] == "Accidents (unintentional injuries) (V01-X59,Y85-Y86)": 62 | if xs[3] == 'New York': 63 | accum_year.append(int(xs[0])) 64 | accum_count_ny.append(int(xs[4])) 65 | if xs[3] == 'North Dakota': 66 | accum_count_nd.append(int(xs[4])) 67 | fig, ax = plt.subplots() 68 | plt.title('Accidental deaths in New York and North Dakota vs. Time') 69 | plt.plot(accum_year, accum_count_ny, label = "# of Deaths in New York") 70 | plt.plot(accum_year, accum_count_nd, label = "# of Deaths in North Dakota") 71 | plt.xticks(np.arange(min(accum_year), max(accum_year)+1, 3.0)) 72 | plt.xlabel('Time (years)') 73 | plt.ylabel('# of Deaths') 74 | plt.legend() 75 | plt.show() 76 | 77 | ''' 78 | fig, ax = plt.subplots() 79 | ax.bar(state_accumulator, count_accumulator_acc) 80 | plt.title('Causes of Death in 2017: Accidents and Alzheimer\'s disease vs. states starting with the letter A') 81 | plt.xlabel('Causes of Death') 82 | plt.ylabel('# of Deaths') 83 | plt.savefig('death_plots.png') 84 | plt.show() 85 | ''' 86 | 87 | 88 | 89 | 90 | 91 | --------------------------------------------------------------------------------