Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在python中从列表中提取元素时会丢失数值精度?_Python_Pandas_Floating Point_Precision - Fatal编程技术网

为什么在python中从列表中提取元素时会丢失数值精度?

为什么在python中从列表中提取元素时会丢失数值精度?,python,pandas,floating-point,precision,Python,Pandas,Floating Point,Precision,我有一个熊猫数据框,看起来像这样: data 0 [26.113017616106, 106.948066803935, 215.488217... 1 [26.369709448639, 106.961107298101, 215.558911... 2 [26.261267444521, 106.991763898421, 215.384122... 3 [26.285746968657, 106.912377030428, 2

我有一个熊猫数据框,看起来像这样:

                    data
0    [26.113017616106, 106.948066803935, 215.488217...
1    [26.369709448639, 106.961107298101, 215.558911...
2    [26.261267444521, 106.991763898421, 215.384122...
3    [26.285746968657, 106.912377030428, 215.287348...
4    [26.155342026996, 106.825440402654, 215.114619...
5    [26.159917638984, 106.819720887669, 215.117593...
6    [26.023564401739, 106.843056508808, 215.129947...
7    [26.1155342027, 106.828185769847, 215.15991763...
8    [26.028826355525, 106.841912605811, 215.146190...
9    [26.015099519561, 106.824296499657, 215.130404...
我试图使用以下代码从一系列列表中提取第一个元素:

[x[1] for x in df.data]
我得到了这个结果:

0    106.948067
1    106.961107
2    106.991764
3    106.912377
4    106.825440
5    106.819721
6    106.843057
7    106.828186
8    106.841913
9    106.824296

为什么会丢失精度?我可以做些什么来保持精度?

默认情况下,pandas显示精度为6位的浮点值

您可以使用pandas的set_选项控制精度,例如:

pd.set_option('precision', 12)

默认情况下,pandas显示精度为6位的浮点值

您可以使用pandas的set_选项控制精度,例如:

pd.set_option('precision', 12)
你可能没有失去精确性。这只是默认显示。例如,如果您使用
s.iloc[0]
获取该系列的项目,您将看到更多的数字,您可能不会失去精度。这只是默认显示。例如,如果您使用
s.iloc[0]
获取该系列的项目,您将看到更多的数字