for my computer science homework im supposed to calculate someones carbon footprint in python. we were given a database,

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

for my computer science homework im supposed to calculate someones carbon footprint in python. we were given a database,

Post by answerhappygod »

for my computer science homework im supposed to calculate
someones carbon footprint in python. we were given a database,
which is sorted into categories, subcategories, grams of carbon,
and frequency of carbon consumed per year. I have finished all of
my questions but one, which requires the addition of many
categories (cars + traveling on airplanes + packaging) times the
frequencies they occur per year. I am trying to put that into my
code, but keep getting a 0 output (see below for pictures). An eco
friendly person is supposed to have 25% less carbon usage than the
average, and the high consumer 25% more. how do i fix this so i no
longer have a 0 output.
if i call just one of the categories, it returns a non zero
output of the number it should be, but as soon as i try to add the
categories together i get a 0 output.
For My Computer Science Homework Im Supposed To Calculate Someones Carbon Footprint In Python We Were Given A Database 1
For My Computer Science Homework Im Supposed To Calculate Someones Carbon Footprint In Python We Were Given A Database 1 (87.25 KiB) Viewed 44 times
For My Computer Science Homework Im Supposed To Calculate Someones Carbon Footprint In Python We Were Given A Database 2
For My Computer Science Homework Im Supposed To Calculate Someones Carbon Footprint In Python We Were Given A Database 2 (7.74 KiB) Viewed 44 times
import numpy as np # mathematical operations etc. import matplotlib.pyplot as plt # plot library import pandas as pd filename = '/Users/Desktop/20220503_python_input_template.csv' df = pd. read_csv(filename, delimiter=';', decimal=",, na_values=-9999.99) # define columns, 1st line is header cat = df [ "Category"] subcat = df ["Sub-category"] m_p = df [ "mass carbon per item (g)"] freq = df [ "Frequency as factor") total = @ ###1.) are you an average, above average or eco consumer print("Which best describes you?\n1) Eco Friendly \n2) Ready to Reduce \n3) High Consumer of carbon") val1 = int(input("Enter value: ")) info = df.loc(cat.str.contains("Traveling", case=False)] info = df.loc[cat.str.contains ("Cars", case=False)] info = df.loc(cat.str.contains ("Packaging", case=False)] idx=df.index [cat=='Traveling 'l idy=df.index [cat== 'Cars'] idz=df.index [cat== 'Packaging 'l a = m_p.iloc[idx) *freq.iloc [idx) b = m_p.iloc[idz) *freq.iloc[idz) C = m_p.iloc(idy] *freq.iloc [idy] d = a + b + c if vall == 1: totalus d avg = 0.25 elif vall == 2: total+= d avg = 1 elif vali -- 3: total+= m_p.iloc [idz) *freq.iloc[idz] avg = 1.25 else: print ('error') total_1= total.sum()*avg print(total_1)]

Which best describes you? 1) Eco Friendly 2) Ready to Reduce 3) High Consumer of plastics Enter value: 1 0.0 In [2]: |
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply