文本文件更改问题

2024-09-28 03:15:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到了一个文本文件,上面有一堆数据以及输出散点图的代码,我需要做的是使用文本文件中的变量来计算一个新变量a_mag,以替换图上给定的v_mag,但我仍停留在以下几行:

for line in lines:
    column = line.split()    
    starID.append(float(column[0]))
    v_mag.append(float(column[1]))
    b_v.append(float(column[2]))
    parallaxes.append(float(column[3]))
    parallax_error.append(float(column[4]))
    d.append(float(1/column[3])) # Distance to star
    a_mag.append(float(column[1]-(5*math.log10(1/column[3]/10))))

da_mag是新的变量,d仅用于计算a_mag,错误代码如下:

 22     parallaxes.append(float(column[3]))
 23     parallax_error.append(float(column[4]))
---> 24     float(d.append(1/column[3])) # Distance to star
 25     a_mag.append(float(Column[1]-(5*math.log10(1/Column[3]/10)))) # Absolute V Magnitude
 26 

TypeError: unsupported operand type(s) for /: 'int' and 'str'

提前感谢:)


Tags: toforlinecolumnerrormathfloatstar
1条回答
网友
1楼 · 发布于 2024-09-28 03:15:08

无论出于何种原因,在第24行和第25行中,将float放在每个单独的“column[x]”之前,都可以解决这个问题

相关问题 更多 >

    热门问题