I am a student and haven’t a big expirence to do this work.
So problem is next.
I have a part of code:
import matplotlib.pyplot as plt
from pylab import *
import cmath
def sf(prompt):
""" """
error_message = "Value must be integer and greater or equal than zero"
while True:
val = raw_input(prompt)
try:
val = float(val)
except ValueError:
print(error_message)
continue
if val <= 0:
print(error_message)
continue
return val
def petrogen_elements():
"""Input and calculations the main parameters for
pertogen elements"""
print "Please enter Petrogen elements: \r"
SiO2 = sf("SiO2: ")
Al2O3= sf("Al2O3: ")
Na2O = sf("Na2O: ")
K2O = sf("K2O: ")
petro = [SiO2,TiO2,Al2O3,]
Sum = sum(petro)
Alcal = Na2O + K2O
TypeA lcal= Na2O / K2O
Ka= (Na2O + K2O)/ Al2O3
print '-'*20, "\r Alcal: %s \r TypeAlcal: %s \
\r Ka: %s \r" % (Alcal, TypeAlcal,Ka,)
petrogen_elements()
So the problem is next. I have to load and read excel file and read all data in it. After that program have to
calculate for example Alcaline, Type of Alcaline etc.
Excel file has only this structure
1 2 3 4 5
1 name1 SiO2 Al2O3 Na2O K2O
2 32 12 0.21 0.1
3 name2 SiO2 Al2O3 Na2O K2O
4 45 8 7.54 5
5 name3 SiO2 Al2O3 Na2O K2O
6. … …. …. …
…
…
All excel file has only 5 columns and unlimited rows.
User has choice input data or import excel file.
First part of work I have done but it stays a big part
Finally I need to read all file and calculate the values.
I would be so grateful for some advice
There is this website http://www.python-excel.org/ that lists all the major Python excel related libraries.
I personally have tried XLRD -the first one listed- and found it great, and it has a neat documentation.
I have also done some work using it while the Presidential elections took place in Egypt as there were lots of data in an excel sheet that we needed to import into a mysql database. I have published the code on Github : https://github.com/mos3abof/egypt-elections-misc
First install xlrd
The script you will come up with should be something like:
You can find a working example from the script I mentioned above in this file : https://github.com/mos3abof/egypt-elections-misc/blob/master/elections_import_excel.py