如何使用 Excel 正确读取带点分隔符的小数?

How to read in decimals with dot-seperator correctly with Excel?

我正在尝试读取 Excel 中的 CSV 文件,其中包含有多个小数位的小数。 我的程序:

  1. 单击数据上方的标签
  2. 点击来自 Text/CSV
  3. 选择我要阅读的文件
  4. 点击加载

如果我用文本编辑器打开 csv,文件如下所示:

Label pre-annotated,Label self-annotated,Begin pre-annotated,End pre-annotated,Begin self-annotated,End self-annotated,Difference Begin,Difference End
P,P,0,3.36998958333333,0,3.36998958333333,0,0.0
P,P,5.50998958333333,5.85998958333333,5.50998958333333,5.85998958333333,0.0,0.0
P,P,6.37998958333333,6.67998958333333,6.37998958333333,6.67998958333333,0.0,0.0
P,P,6.80998958333333,7.80998958333333,6.80998958333333,7.80998958333333,0.0,0.0
P,COND1,10.3299895833333,10.36996875,10.3299895833333,10.517009268921914,0.0,0.14704051892191394

小数点以点开头。 但是,将其加载到 Excel 后,点无法识别,table 看起来如下:

我尝试将 Excel 小数点分隔符更改为点和逗号,但没有帮助。即使在 Windows 中将小数点分隔符更改为点,它也不起作用。

如有任何帮助,我们将不胜感激。

正如评论所指出的,这似乎是分隔符的区域性问题。更改 Windows 系统或 Excel 中的分隔符对解决此问题没有帮助。

我发现 的解决方法是在文本编辑器中将 SEP= 作为第一行添加到我的 CSV 文件中。

在 PQ 中,您需要 change type using locale(在本例中为英语-美国)。

选择一列或多列后,您可以在右键单击下拉菜单中找到它。

PQ 将相应地解释分隔符。

您示例的 MCode 为:

#"Changed Type with Locale" = Table.TransformColumnTypes(#"Promoted Headers", {{"Begin pre-annotated", type number}, {"End pre-annotated", type number}, {"Begin self-annotated", type number}, {"End self-annotated", type number}, {"Difference Begin", type number}, {"Difference End", type number}}, "en-US")

注意 "en-US" 用于 Table.TransformColumnTypes 函数的可选 culture 参数