【发布时间】:2020-07-09 16:08:36
【问题描述】:
有人可以帮忙处理这段代码吗?我正在编写这段代码来计算一些方程的一些值。我通过将 CSV 值读入字典,但在计算出最终参数集的值后,我找不到在同一个列表上重复迭代的方法。
简单来说,我有两个输入列表 dPdT 和 listT。我需要在 listT 上迭代列表 dPdT 的每个参数并生成三个不同的列表 P。
我感谢任何愿意提供帮助的人。这是一个课程的学习项目。
# Request user's interval parameters for calculations
print("Inform the temperature range and interval (°C). Only integers.")
minT = int(input("Min: "))
maxT = int(input("Max: "))
stepT = int(input("Temperature interval: "))
# create a list of temperature values to compute pressure parameters
listT = []
for x in range(minT, (maxT+stepT), stepT):
listT.append(x)
# Open CSV file in read mode to acces data and read it into a dictionary
with open(CSVfile, "r") as CSV:
reader = csv.DictReader(CSV)
listDict = []
# Creates a list of dictionaries with the fluid inclusion parameters
for lines in reader:
listDict.append(lines)
# Define list parameters to be computated
a, b, c, dPdT, P = [], [], [], [], []
# Loop iterates over the dictionary list and computates parameters a,b,c stored in lists a,b,c
for i, rows in enumerate(listDict):
a.append(i)
b.append(i)
c.append(i)
if "sal" in rows:
a[i] = (18.28 + 1.4413 * float(rows["sal"]) + 0.0047241 * float(rows["sal"]) ** 2
+ 0.0024213 * float(rows["sal"]) ** 3 + 0.000038064 * float(rows["sal"]) ** 4)
b[i] = (0.019041 - 1.4268 * 0.01 * float(rows["sal"]) + 5.66012 * 0.0001 * float(rows["sal"]) ** 2
- 4.2329 * 0.000001 * float(rows["sal"]) ** 3 - 3.0354 * 0.00000001 * float(rows["sal"]) ** 4)
c[i] = (- 1.5988 * 0.0001 + 3.6892 * (10 ** -5) * float(rows["sal"]) - 1.9473 * (10 ** -6) * float(rows["sal"]) ** 2
+ 4.1674 * (10 ** -8) * float(rows["sal"]) ** 3 - 3.3008 * (10 ** -10) * float(rows["sal"]) ** 4)
# Loop iterates over the dictionary list and computates dPdT to store the values in list dPdT
for i, rows in enumerate(listDict):
dPdT.append(i)
if "th" in rows:
dPdT[i] = a[i] + b[i] * float(rows["th"]) + c[i] * float(rows["th"]) ** 2
# Loop populates list P (pressure values)
for i in range(len(listT)):
P.append(i)
# problem starts here: I need to iterate over the listT or P, repeating it for every dPdT values.
# Loop to calculate P based on lits dPdT and listT.
while i in range(len(dPdT)):
for j in range(len(P)):
P[j] = dPdT[j] * listT[j]
【问题讨论】:
-
你能链接错误信息吗?
-
还没有错误信息。我不能只是想办法解决这个问题。
标签: python data-science data-analysis