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.
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]: |
for my computer science homework im supposed to calculate someones carbon footprint in python. we were given a database,
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am