快速矿工:CSV,包含实数,用逗号代替点

发布于 2024-11-05 06:40:55 字数 335 浏览 8 评论 0原文

我在使用 RapidMiner 导入 CSV 文件时遇到问题。 浮点值用逗号代替整数和小数值之间的分隔点。

有人知道如何正确导入以这种方式格式化的值吗?

示例数据:

<代码> BMI;1;0;1;1;1;蓝色;-0,138812155;0,520378909;5;0;50;107;0;9;0;其他;良好;2011 BMI;1;0;1;1;1;粉红色;-0,624654696;;8;0;73;120;1;3;0,882638889;其他;好;2011

Rapid miner 实际上将其解释为“多项式”。强制其为“真实”只会导致对“0”值的正确解释。

谢谢

I have a problem importing a CSV file with RapidMiner.
Floating point values are written with commas instead of the separating dot between the integer and decimal values.

Anyone know how to import correctly the values formatted in this way?

sample data:


BMI;1;0;1;1;1;blue;-0,138812155;0,520378909;5;0;50;107;0;9;0;other;good;2011
BMI;1;0;1;1;1;pink;-0,624654696;;8;0;73;120;1;3;0,882638889;other;good;2011

Rapid miner actually interprets it as "polynomial". Forcing it to "real" leads only to a correct interpretation of the "0" value.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潜移默化 2024-11-12 06:40:55

这似乎是一个非常古老的请求。不确定这是否会对您有帮助,但这可能会对其他有类似情况的人有所帮助。

第 1 步:在“读取 CSV”操作符中的“导入配置向导”下,确保选择“分号”作为分隔符

第 2 步:使用“猜测类型”操作符。属性过滤器类型 ->子集,选择属性->选择属性 8、9 和 16(基于上面的示例),将“小数点字符”更改为“,”,您应该已全部设置完毕。

希望这可以帮助(某人!)

This seems to be a very old request. Not sure if this will help you, but this may help others with a similar situation.

Step 1: in the "Read CSV" operator, under "import configuration wizard", make sure you select "Semicolon" as the separator

Step 2: use the "Guess Types" operator. Attribute Filter Type -> Subset, Select Attributes -> select the attributes 8, 9 and 16 (based on your example above), change "decimal point character" to a "," and you should be all set.

Hope this helps (someone!)

对岸观火 2024-11-12 06:40:55

使用分号作为分隔符。您可以使用 java.util.Scanner 来读取每一行。 String.split() 在分号上分割。当您获得带有逗号的标记时,可以使用 String.replace() 将逗号更改为小数。然后你可以使用 Float.parseFloat()

希望这能回答你的问题。

Use semi-colon as the delimiter. You can use java.util.Scanner to read each line. String.split() to split on the semi-colon. When you get a token with a comma you can use String.replace() to change the comma to a decimal. Then you can use Float.parseFloat()

Hope this answers you question.

你在看孤独的风景 2024-11-12 06:40:55
public static void main(String args){
    BufferedReader br = new BufferedReader(new FileReader("c:\\path\\semicolons and numbers and commas.csv"));
    try {
        for(String line; (line=br.readLine()) != null);) {
            //Variable line now has a single line from the file. This code will execute for each line.
            String array = line.split(";");// Split on the semicolon. Beware of changing this. This uses regex which means that some characters mean something like . means anything, not just dots.
            double firstDouble = Double.parseDouble(array[7].replace(',','.')); // Get field 7 (the eighth field) and turn it into a double (high precision floating point). Replace , with . so it will not make an error
            System.err.println("Have a number " + firstDouble);
            System.err.println("Can play with it " + (firstDouble * 2.0));
        }
    }finally{
        br.close(); // Free resources (and unlock file on Windows).
    }
}
public static void main(String args){
    BufferedReader br = new BufferedReader(new FileReader("c:\\path\\semicolons and numbers and commas.csv"));
    try {
        for(String line; (line=br.readLine()) != null);) {
            //Variable line now has a single line from the file. This code will execute for each line.
            String array = line.split(";");// Split on the semicolon. Beware of changing this. This uses regex which means that some characters mean something like . means anything, not just dots.
            double firstDouble = Double.parseDouble(array[7].replace(',','.')); // Get field 7 (the eighth field) and turn it into a double (high precision floating point). Replace , with . so it will not make an error
            System.err.println("Have a number " + firstDouble);
            System.err.println("Can play with it " + (firstDouble * 2.0));
        }
    }finally{
        br.close(); // Free resources (and unlock file on Windows).
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文