Java Code Examples for tech.tablesaw.api.IntColumn#append()
The following examples show how to use
tech.tablesaw.api.IntColumn#append() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SawReader.java From tablesaw with Apache License 2.0 | 6 votes |
private static IntColumn readIntColumn(String fileName, ColumnMetadata metadata) throws IOException { IntColumn ints = IntColumn.create(metadata.getName()); try (FileInputStream fis = new FileInputStream(fileName); SnappyFramedInputStream sis = new SnappyFramedInputStream(fis, true); DataInputStream dis = new DataInputStream(sis)) { boolean EOF = false; while (!EOF) { try { ints.append(dis.readInt()); } catch (EOFException e) { EOF = true; } } } return ints; }
Example 2
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
default IntColumn difference(TimeColumn column2, ChronoUnit unit) { IntColumn newColumn = IntColumn.create(name() + " - " + column2.name() + "[" + unit.name() + "]"); for (int r = 0; r < size(); r++) { int c1 = this.getIntInternal(r); int c2 = column2.getIntInternal(r); if (TimeColumn.valueIsMissing(c1) || TimeColumn.valueIsMissing(c2)) { newColumn.append(IntColumnType.missingValueIndicator()); } else { LocalTime value1 = PackedLocalTime.asLocalTime(c1); LocalTime value2 = PackedLocalTime.asLocalTime(c2); if (value1 != null && value2 != null) { newColumn.append((int) unit.between(value1, value2)); } else { newColumn.appendMissing(); } } } return newColumn; }
Example 3
Source File: DateTimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn secondOfDay() { IntColumn newColumn = IntColumn.create(name() + "[" + "second-of-day" + "]"); for (int r = 0; r < size(); r++) { if (!isMissing(r)) { long c1 = getLongInternal(r); newColumn.append(getSecondOfDay(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 4
Source File: DateTimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn minuteOfDay() { IntColumn newColumn = IntColumn.create(name() + "[" + "minute-of-day" + "]"); for (int r = 0; r < size(); r++) { if (!isMissing(r)) { long c1 = getLongInternal(r); newColumn.append((short) getMinuteOfDay(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 5
Source File: IntDictionaryMap.java From tablesaw with Apache License 2.0 | 5 votes |
/** */ @Override public Table countByCategory(String columnName) { Table t = Table.create("Column: " + columnName); StringColumn categories = StringColumn.create("Category"); IntColumn counts = IntColumn.create("Count"); // Now uses the keyToCount map for (Map.Entry<Integer, Integer> entry : keyToCount.int2IntEntrySet()) { categories.append(getValueForKey(entry.getKey())); counts.append(entry.getValue()); } t.addColumns(categories); t.addColumns(counts); return t; }
Example 6
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn secondOfDay() { IntColumn newColumn = IntColumn.create(name() + "[" + "second-of-day" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getSecondOfDay(c1)); } else { newColumn.append(IntColumnType.missingValueIndicator()); } } return newColumn; }
Example 7
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn minuteOfDay() { IntColumn newColumn = IntColumn.create(name() + "[" + "minute-of-day" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getMinuteOfDay(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 8
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn milliseconds() { IntColumn newColumn = IntColumn.create(name() + "[" + "ms" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getMilliseconds(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 9
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn second() { IntColumn newColumn = IntColumn.create(name() + "[" + "second" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getSecond(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 10
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn hour() { IntColumn newColumn = IntColumn.create(name() + "[" + "hour" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getHour(c1)); } else { newColumn.append(IntColumnType.missingValueIndicator()); } } return newColumn; }
Example 11
Source File: TimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn hour() { IntColumn newColumn = IntColumn.create(name() + "[" + "hour" + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); if (!TimeColumn.valueIsMissing(c1)) { newColumn.append(PackedLocalTime.getHour(c1)); } else { newColumn.append(IntColumnType.missingValueIndicator()); } } return newColumn; }
Example 12
Source File: DateTimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn hour() { IntColumn newColumn = IntColumn.create(name() + "[" + "hour" + "]"); for (int r = 0; r < size(); r++) { if (!isMissing(r)) { long c1 = getLongInternal(r); newColumn.append(getHour(c1)); } else { newColumn.appendMissing(); } } return newColumn; }
Example 13
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn dayOfYear() { IntColumn newColumn = IntColumn.create(this.name() + " day of year"); for (int r = 0; r < this.size(); r++) { int c1 = this.getIntInternal(r); if (valueIsMissing(c1)) { newColumn.appendMissing(); } else { newColumn.append((short) PackedLocalDate.getDayOfYear(c1)); } } return newColumn; }
Example 14
Source File: DateTimeMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn year() { IntColumn newColumn = IntColumn.create(this.name() + " year"); for (int r = 0; r < this.size(); r++) { if (isMissing(r)) { newColumn.appendMissing(); } else { long c1 = getLongInternal(r); newColumn.append(PackedLocalDate.getYear(PackedLocalDateTime.date(c1))); } } return newColumn; }
Example 15
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Calculates the temporal difference between each element of the receiver and the respective * element of the argument * * <p>Missing values in either result in a Missing Value for the new column */ default IntColumn timeUntil(DateColumn end, ChronoUnit unit) { IntColumn newColumn = IntColumn.create(name() + " - " + end.name() + "[" + unit.name() + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); int c2 = end.getIntInternal(r); if (valueIsMissing(c1) || valueIsMissing(c2)) { newColumn.appendMissing(); } else { switch (unit) { case DAYS: newColumn.append(PackedLocalDate.daysUntil(c2, c1)); break; case WEEKS: newColumn.append(PackedLocalDate.weeksUntil(c2, c1)); break; case MONTHS: newColumn.append(PackedLocalDate.monthsUntil(c2, c1)); break; case YEARS: newColumn.append(PackedLocalDate.yearsUntil(c2, c1)); break; default: // handle decades, etc. LocalDate value1 = PackedLocalDate.asLocalDate(c1); LocalDate value2 = PackedLocalDate.asLocalDate(c2); if (value1 == null || value2 == null) { newColumn.appendMissing(); } else { newColumn.append((int) unit.between(value1, value2)); } break; } } } return newColumn; }
Example 16
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Calculates the temporal difference between each element of the receiver and the respective * element of the argument * * <p>Missing values in either result in a Missing Value for the new column */ default IntColumn timeUntil(DateColumn end, ChronoUnit unit) { IntColumn newColumn = IntColumn.create(name() + " - " + end.name() + "[" + unit.name() + "]"); for (int r = 0; r < size(); r++) { int c1 = getIntInternal(r); int c2 = end.getIntInternal(r); if (valueIsMissing(c1) || valueIsMissing(c2)) { newColumn.appendMissing(); } else { switch (unit) { case DAYS: newColumn.append(PackedLocalDate.daysUntil(c2, c1)); break; case WEEKS: newColumn.append(PackedLocalDate.weeksUntil(c2, c1)); break; case MONTHS: newColumn.append(PackedLocalDate.monthsUntil(c2, c1)); break; case YEARS: newColumn.append(PackedLocalDate.yearsUntil(c2, c1)); break; default: // handle decades, etc. LocalDate value1 = PackedLocalDate.asLocalDate(c1); LocalDate value2 = PackedLocalDate.asLocalDate(c2); if (value1 == null || value2 == null) { newColumn.appendMissing(); } else { newColumn.append((int) unit.between(value1, value2)); } break; } } } return newColumn; }
Example 17
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Returns an IntColumn containing all the values of this string column as integers, assuming all * the values are stringified ints in the first place. Otherwise an exception is thrown * * @return An IntColumn containing ints parsed from the strings in this column */ default IntColumn parseInt() { IntColumn newColumn = IntColumn.create(name() + "[parsed]"); for (String s : this) { if (StringColumn.valueIsMissing(s)) { newColumn.appendMissing(); } else { newColumn.append(Integer.parseInt(s)); } } return newColumn; }
Example 18
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn monthValue() { IntColumn newColumn = IntColumn.create(this.name() + " month"); for (int r = 0; r < this.size(); r++) { int c1 = this.getIntInternal(r); if (DateColumn.valueIsMissing(c1)) { newColumn.appendMissing(); } else { newColumn.append(PackedLocalDate.getMonthValue(c1)); } } return newColumn; }
Example 19
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn dayOfYear() { IntColumn newColumn = IntColumn.create(this.name() + " day of year"); for (int r = 0; r < this.size(); r++) { int c1 = this.getIntInternal(r); if (valueIsMissing(c1)) { newColumn.appendMissing(); } else { newColumn.append((short) PackedLocalDate.getDayOfYear(c1)); } } return newColumn; }
Example 20
Source File: DateMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
default IntColumn dayOfMonth() { IntColumn newColumn = IntColumn.create(this.name() + " day of month"); for (int r = 0; r < this.size(); r++) { int c1 = this.getIntInternal(r); if (valueIsMissing(c1)) { newColumn.appendMissing(); } else { newColumn.append(PackedLocalDate.getDayOfMonth(c1)); } } return newColumn; }