Python help! I am writing a program that reads an excel file to answer some ques
ID: 3712896 • Letter: P
Question
Python help! I am writing a program that reads an excel file to answer some questions. In the data sheet (attached image) each line shows the XRD data of all the materials given a specific Intensity (Arb. Units). AlNi* are the name of the materials. Each column shows the XRD data of one material. I attached a screen shot of the data and what i have done so far for other questions. These are the questions I need to answer. I know how to find an average using sum in python but am not sure how to do it with reading the excel file! Thank you!
What is average intensity?
What is the highest intensity?
What is the lowest intensity?
from math import * file-open("4material.csv","r") lines-file. readlines) # print(lines) attributes-lines [0] . strip ( ) . split (", ") mapA2Index-th index-0 for x in attributes1:] index+-1 spacecount-0 for line in lines [1:]: ) materials-Line. strip( ) . split ( for data in materials [1:]: check-data.strip() if check.isspace(): spacecount++1 elif len (check.split()) spacecount+1 intensitycount-0 for Line in LineSL1: intensitycount+1 zerocount-0 for line in lines [1:]: materials-line.strip().split(',') for data in materials [1:]: check-data.strip() if check"0": zerocount+-1 print("How many materials the data has:", index) print("How many missing values the data has:", spacecount) print("How many different intensities the data has:", intensitycount) print "How many zeros the data has:", zerocount)Explanation / Answer
#looking forward to your feedback
total_intensity = 0
highest_intensity = 0
lowest_intensity = 32565
for line in lines[1:]:
materials = line.strip().split(',')
if float(materials[0]) > highest_intensity:
highest_intensity = float(materials[0])
elif float(materials[0]) < lowest_intensity:
lowest_intensity = float(material[0])
total_intensity += float(material[0])
average_intensity = total_intensity/len(lines[1:])
print("average intensity of materials is ", average_intensity)
print("highest intensity among materials is ", highest_intensity)
print("lowest intensity among materials is ", lowest_intensity)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.