2011-05-04 22 views
0

使用RapidMiner導入CSV文件時出現問題。 浮點值用逗號而不是整數和小數值之間的分隔點寫入。快速採礦者:帶有逗號而不是點的實數的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

快速礦工實際上將其解釋爲 「多項式」。將它強制爲「真實」只會導致對「0」值的正確解釋。

謝謝

+1

,你能否告訴我們CSV的幾排,所以我們可以測試我們可能會拿出解決方案,而不是找出後,他們錯了嗎? – 2011-05-04 20:01:16

+0

是的。剛剛做到了。 – fstab 2011-05-04 20:04:00

回答

0

使用分號作爲分隔符。您可以使用java.util.Scanner來讀取每一行。 String.split()分割在分號上。當用逗號得到令牌時,可以使用String.replace()將逗號更改爲小數點。那麼你可以使用Float.parseFloat()

希望這回答你的問題。

+0

感謝您的回答。不幸的是,我剛剛開始學習RapidMiner,只使用GUI。 GUI沒有任何簡單的方法嗎? – fstab 2011-05-04 20:20:32

+0

對不起。我不熟悉RapidMiner。祝你好運。 – JustinKSU 2011-05-04 22:04:40

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). 
    } 
} 
3

這似乎是一個非常古老的要求。不知道這是否會對你有幫助,但這可能會幫助其他人也有類似的情況。

第1步:在「讀CSV」操作,在「導入配置嚮導」,請確保您選擇「分號」作爲分隔符

第2步:使用「猜猜類型」操作。屬性過濾器類型 - >子集,選擇屬性 - >選擇屬性8,9和16(基於上述示例),將「小數點字符」更改爲「,」並且應該全部設置。

希望這有助於(一個人!)