我只是从python开始,并针对此错误。谁会知道为什么以及是否要将数据保存为整数或如何做到这一点?
Traceback (most recent call last):
File "C:\Users\Gabriela Lammoglia\AppData\Local\Programs\Python\Python37-32\open.py", line 34, in <module>
latt2=mult*lattice
代码:
from csv import reader
from collections import defaultdict
from ast import literal_eval
from pprint import pprint
data = defaultdict(list)
with open('crystal.csv') as f:
csv_reader = reader(f)
current_header = None
for line in csv_reader:
# We found a header
if len(line) == 1 and all(item.isalpha() or item.isspace() for item in line[0]):
current_header = line[0]
# Otherwise normal line with ints and floats
else:
data[current_header].append(list(map(literal_eval, line)))
pprint(data)
mult=data['multiplicty']
lattice=data['lattice parameters']
occup=data['occupancy']
sites=data['atom sites']
print(mult)
print(lattice)
print(occup)
print(sites)
import numpy as np
latt2=mult*lattice
答案 0 :(得分:-2)
latt2=int(mult)*lattice
您需要将多值设为整数。现在,您尝试使用多个字符串和列表,这是个坏主意。