我已经在Pycharm中编写了一段代码,该代码似乎可以完美执行,但是只要将代码放入Jupyter笔记本中,我就会收到消息: (图片)
这是我的代码(Python):
def parse_planets_file(fname):
with open(fname) as f:
inputm = f.readlines()
method = inputm[0].split(",")
del inputm[0]
del method[0]
data = {}
for row in inputm:
row = (row.strip()).split(",")
if row[0] not in data:
data[row[0]] = {h.strip(): [] for h in method}
for i, h in enumerate(method):
h = h.strip()
data[row[0]][h].append(float(row[i + 1]) if row[i + 1] else row[i + 1])
return data
fname = "exoplanets.csv"
print(parse_planets_file(fname))
执行Pycharm中的确切代码,我没有收到任何错误。有人可以帮助我吗?