Skip to content

Instantly share code, notes, and snippets.

@manoelcampos
Created October 17, 2020 13:51
Show Gist options
  • Save manoelcampos/3bf71f76991f091a5a68a866a42518a6 to your computer and use it in GitHub Desktop.
Save manoelcampos/3bf71f76991f091a5a68a866a42518a6 to your computer and use it in GitHub Desktop.
d3x-morpheus DataFrame row/column removal issue
import com.d3x.morpheus.array.Array;
import com.d3x.morpheus.frame.DataFrame;
import com.d3x.morpheus.frame.DataFrameValue;
import java.util.List;
public class DataFrameRowColRemoval {
public static void main(String[] args) {
new DataFrameRowColRemoval();
}
private DataFrameRowColRemoval(){
final var rows = Array.of(0, 1, 2, 3, 4);
final var cols = Array.of('A', 'B', 'C', 'D', 'E', 'F');
final var colsToRemove = List.of('B', 'D', 'F');
final var rowsToRemove = List.of(0, 1);
final var frame = DataFrame.ofInts(rows, cols);
frame.applyValues(this::generateValue);
print("Frame before column removal", frame);
final var newFrame =
frame.cols().remove(col -> colsToRemove.contains(col.key()))
.rows().remove(row -> rowsToRemove.contains(row.key()));
print("Frame after column removal", newFrame);
}
private void print(String title, DataFrame<Integer, Character> frame) {
System.out.println(title);
System.out.print(" ");
frame.cols().forEach(col -> System.out.printf("%3c ", col.key()));
System.out.println();
frame.rows().forEach(row -> {
System.out.printf("%2d | ", row.key());
row.forEach(val -> System.out.printf("%3d ", val.getInt()));
System.out.println();
});
System.out.println();
}
private int generateValue(DataFrameValue<Integer, Character> val){
return (val.rowOrdinal() + val.colOrdinal() * val.frame().rowCount()) + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment