hi:) i am trying to make a for loop to reduce redundancy in my code, where i need to access a number of different sheets within an excel file, count the number of specific values and later plot a graph. my code for my for loop looks like this at the moment:
df = pd.read_excel('C:/Users/julia/OneDrive/Documents/python assignment/2016 data -EU values.xlsx',
skiprows=6)
sheets_1 = ["PM10 ", "PM2.5", "O3 ", "NO2 ", "BaP", "SO2"]
resultM1 = 0
for sheet in sheets_1:
print(sheet[0:5])
for row in df.iterrows():
if row[1]['Country'] == 'Malta':
resultM1 += row[1]['AirPollutionLevel']
print(resultM1)
i would like for the output to look something like this: PM10 142 PM2.5 53 O3 21 NO2 3 BaP 21 SO2 32
but what i'm getting is just the sheet names printed after each other and the total amount of the sepcific value i need across all sheets. i.e. PM10 PM2.5 O3 NO2 BaP SO2 284.913786
i really need the values separated into their respective sheet and not added together.
attached is a screeshot of the excel file. as u can see, there are different sheets and many values within -i need to add values for a specific country in each sheet.
any help would be greatly appreciated!