我有一个问题导入CSV文件与RapidMiner。浮点值写入时使用逗号,而不是整数和十进制值之间的分隔点。
有人知道如何正确导入以这种方式格式化的值吗?
样本数据:
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实际上将其解释为"多项式"。强制它为"real"只会导致对"0"值的正确解释。
谢谢
这似乎是一个非常古老的请求。我不确定这是否对你有帮助,但这可能对遇到类似情况的其他人有帮助。
步骤1:在"读取CSV"操作符中,在"导入配置向导"下,确保选择"分号"作为分隔符
步骤2:使用"Guess Types"操作符。属性筛选类型->子集,选择属性->选择属性8,9和16(基于上面的示例),将"小数点字符"更改为",",然后应该都设置好了。
希望能帮到你
使用分号作为分隔符。您可以使用java.util.Scanner
读取每一行。String.split()
在分号上分裂。当您得到一个带有逗号的令牌时,您可以使用String.replace()
将逗号更改为小数。然后你可以使用Float.parseFloat()
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).
}
}