jtablesaw / tablesaw

Java dataframe and visualization library
https://jtablesaw.github.io/tablesaw/
Apache License 2.0
3.56k stars 645 forks source link

stringColumn转换成doubleColunm后,值不对 #1177

Open PanYangyi opened 1 year ago

PanYangyi commented 1 year ago

hi~,您好。tablesaw 非常的棒,但是在使用tablesaw过程中遇见了一些问题,希望能够给予帮助。 问题描述: 因为doubleColunm不能splitOn,所以我将doubleColunm as stringColumn后进行了分组切片,最后将stringColumn还原成doubleColumn的时候,值却出现了问题。 code :

@Test
public void test000() {
    DoubleColumn doubleColumn = DoubleColumn.create("year", 2022.0, 2022.0);
    StringColumn stringColumn = doubleColumn.asStringColumn();
    System.out.println(stringColumn.print());
    DoubleColumn asDoubleColumn = stringColumn.asDoubleColumn();
    System.out.println(asDoubleColumn.print());
}

输出: Column: year strings 2022.0 2022.0

Column: year strings 0 0

再次表示感谢🙏

m37r commented 1 year ago

This is actually correct since asDoubleColumn is intended to produce doubles for the categories of the string column, not for its actual string values. This becomes clearer with this modified example:

@Test
public void test000() {
    DoubleColumn doubleColumn = DoubleColumn.create("year", 2022.0, 2022.0, 2023.0);
    StringColumn stringColumn = doubleColumn.asStringColumn();
    System.out.println(stringColumn.print());
    DoubleColumn asDoubleColumn = stringColumn.asDoubleColumn();
    System.out.println(asDoubleColumn.print());
}

yielding

Column: year strings
2022.0
2022.0
2023.0

Column: year strings
0
0
1

To transform the string values back to doubles, use parseDoubles() on the StringColumn.

bobningx commented 1 year ago
  1. DoubleColumn is not a CategoricalColumn, method splitOn only accept CategoricalColumns.
  2. you can use IntColumn for year values
HotchForGDMEC commented 8 months ago

use parseDoubles()

frankwondon commented 8 months ago

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。