小数分隔符问题

时间:2017-10-18 02:15:01

标签: python decimal separator

我有纬度/经度数字,例如:-4726786457893145

但我需要一个小数点分隔符,例如:-47.26786457893145

我尝试了'格式'或'for'结构,但没有成功。我甚至转换为列表,然后插入一个点,然后再转换为浮点数,但不适用于所有数字,我不知道为什么。 我很感激你的帮助。感谢。

这是我的部分代码:

latitude = []
longitude = []
for i in range(len(data['Latitude'])):
    a = list(str(data['Latitude'][i].replace(',','')))
    a.insert(3,'.')
    str1 = ''.join(a)
    latitude.append(float(str1))

    a = list(str(data['Longitude'][i].replace(',','')))
    a.insert(3,'.')
    str1 = ''.join(a)
    longitude.append(float(str1))

2 个答案:

答案 0 :(得分:0)

您似乎正在删除,,而不是尝试将.插入固定位置。用.replace(',','.')替换它们应该更正确 比你的代码片段看起来这样(通过一些简化):

latitude = [lat.replace(',','.') for lat in data['Latitude']]
longitude = [lon.replace(',','.') for lon in data['Longitude']]

答案 1 :(得分:0)

我做的这个功能......可以写得更清楚......将把-4726786457893145变成-47.26786457893145。

Failed to compile.

./node_modules/third-party-package/src/web/testComponent.js
Module parse failed: \node_modules\third-party-package\src\web\testComponent.js Unexpected token (8:6)
You may need an appropriate loader to handle this file type.
|   render() {
|     return (
|       <div>
|         Test component text
|       </div>

jupyter notebook的例子:

enter image description here

相关问题