python 设置文件中数据的读取精度

在使用的是pandas读取文件内的数据时,通常会默认保持7精度左右的数据(具体有多少进度没有在意)

而有时候我们需要精度比较高的数据,在这里就需要进行处理了,

一般需要在使用pandas读取文件的那一行之后,添加一行代码:

1 with pd.option_context('display.precision', 12)

就行了,完整例子如下

point = pd.read_csv('point.csv')
with pd.option_context('display.precision', 12):
    # print(point)
    B0 = np.double(point.loc[0, ['x']])
    L0 = np.double(point.loc[0, ['y']])
    #print(B0, L0)
    for i in range(len(point)):
        if i % 10 == 0:
            waypoint = point.loc[i, ["x", "y", "heading"]].values.astype(float)
            lat = np.double(waypoint[[0]])
            lon = np.double(waypoint[[1]])
            x, y = transformation(lat, lon, B0, L0)
            line = "%s,%s,%s" % (x, y, waypoint[[2]][0])
            with open("test.csv", 'a+') as f:
                f.write(line + '\n')

猜你喜欢

转载自www.cnblogs.com/yang220/p/12202533.html