0

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

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

样本数据:

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 实际上将其解释为“多项式”。将其强制为“真实”只会导致对“0”值的正确解释。

谢谢

4

3 回答 3

3

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

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

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

希望这有助于(某人!)

于 2012-12-04T21:16:57.287 回答
0

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

希望这能回答你的问题。

于 2011-05-04T20:08:01.087 回答
0
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).
    }
}
于 2011-05-04T20:11:06.547 回答