Question
Here is the assignment: Write a program that creates the following 4 histograms based on the data in weight-height.csv: male heights male weights female heights
Here is the assignment:
Write a program that creates the following 4 histograms based on the data in weight-height.csv:
- male heights
- male weights
- female heights
- female weights
Redirect the input from the file into your program. Example with my Windows Computer:
Get-Content weight-height.csv | python weightheight.py
Here are a some lines from the weight-height.csv file (including the header at the top)::
"Gender","Height","Weight" "Male",73.847017017515,241.893563180437 "Male",68.7819040458903,162.310472521300 "Male",74.1101053917849,212.7408555565 "Male",71.7309784033377,220.042470303077 "Male",69.8817958611153,206.349800623871
"Female",58.9107320370127,102.088326367840 "Female",65.2300125077128,141.305822601420 "Female",63.3690037584139,131.041402692995 "Female",64.4799974256081,128.171511221632 "Female",61.7930961472815,129.781407047572 "Female",65.9680189539591,156.802082613991
And here is my code:
male_height = [] female_height = [] male_weight = [] female_weight = [] decoded = [] decoded += stdio.readLine().split(',') decoded.pop(0) decoded.pop(0) decoded.pop(0) for i in decoded: for i in range(0,(len(decoded)): j = decoded[i] if j == 'Male': for i in range(i+1, i+2): if 60.0 < float(j) < 79.0: male_height.append(decoded[j]) elif 79.1 < float(j) < 350.0: male_weight.append(decoded[j]) else: for i in range(i+1, i+2): if 40.0 < float(j) < 75.0: female_height.append(decoded[j]) elif 75.1 < float(j) < 300.0: female_weight.append(decoded[j]) i = (i+3)
male_height.sort() plt.hist(male_height, bins='auto') plt.show() female_height.sort() plt.hist(female_height, bins='auto') plt.show()
male_weight.sort() plt.hist(male_weight, bins='auto') plt.show() female_weight.sort() plt.hist(female_weight, bins='auto') plt.show()
This is to read from a file of heights and weights and to sort them into 4 histograms. I feel like I'm pretty close with this and I want to try to keep it close to what I have since I'm using functions from class but it is creating an infinite loop and never stops graphing. I did some funky stuff with the (i+2) and (i+1) in the middle so it wouldn't try to compare the gender to the weight and height floats but I think that's part of my problem. Please do not use pandas to solve this as we haven't learned that yet so I don't think I'll get credit solving it that way. Thank you!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started