Package com.fahmatrix

Class DataFrame

java.lang.Object
com.fahmatrix.DataFrame

public class DataFrame extends Object
DataFrame is the basic object for hadling data

Current Features:
Select/Add column data
Print in System Console
Print data Summary
Import From CSV/TSV, xlsx
Reverse (transpose) data
Select Row/Column by Label or Position
  • Constructor Details

    • DataFrame

      public DataFrame()
      Constructor with empty indexes and columns
    • DataFrame

      public DataFrame(List<String> index)
      Constructor with known indexes and empty columns
      Parameters:
      index - Array of indexes
    • DataFrame

      public DataFrame(List<String> index, Map<String,List<Object>> columns)
      Constructor with known indexes and columns
      Parameters:
      index - Array of indexes
      columns - Map of data where key is the column name and the value is Array of cells data
  • Method Details

    • addColumn

      public void addColumn(String name, List<Object> data)
      Add column to the end of data table
      Parameters:
      name - index name
      data - column data (Array of cells data)
    • getColumn

      public Series getColumn(String name)
      return a new Series Object with data of only one column
      Parameters:
      name - column name
      Returns:
      Series data with index
    • getColumnsByLabel

      public DataFrame getColumnsByLabel(String... columnLabels)
      Select Columns by name
      this method assumes you selected all rows
      Parameters:
      columnLabels - Basic String Array (String[]) for column names
      Returns:
      New Dataframe with only the selected data
    • getColumnsByPosition

      public DataFrame getColumnsByPosition(int... columnIndices)
      Select certains columns position
      Parameters:
      columnIndices - Basic Integer Array (int[]) for columns position
      Returns:
      New Dataframe with only the selected datas
    • head

      public DataFrame head()
      Return the first 5 rows as DataFrame Object
      Returns:
      first 5 rows
    • head

      public DataFrame head(int n)
      Return the first n rows as DataFrame Object
      Parameters:
      n - the max number of rows to return
      Returns:
      rows
    • tail

      public DataFrame tail()
      Return the last 5 rows as DataFrame Object
      Returns:
      last 5 rows
    • tail

      public DataFrame tail(int n)
      Return the last n rows as DataFrame Object
      Parameters:
      n - the max number of rows to return
      Returns:
      rows
    • transpose

      public DataFrame transpose()
      Reverse Rows and Columns
      Returns:
      new DataFrame with transposed data
    • getByLabel

      public Object getByLabel(String rowLabel, String colLabel)
      Select Cell by row and column name
      Parameters:
      rowLabel - row name
      colLabel - column name
      Returns:
      Object for cell value (String, Float, Double)
    • getRowsByLabel

      public DataFrame getRowsByLabel(String... rowLabels)
      Select Rows by name
      this method assumes you selected all columns
      Parameters:
      rowLabels - Basic String Array (String[]) for rows name
      Returns:
      New Dataframe with only the selected data
    • getByLabels

      public DataFrame getByLabels(String[] rowLabels, String[] colLabels)
      Select certains rows and columns by name
      these names are not Excel A1,B1 names.
      Parameters:
      rowLabels - Basic String Array (String[]) for row names
      colLabels - Basic String Array (String[]) for column names
      Returns:
      New Dataframe with only the selected data
    • getByPosition

      public Object getByPosition(int rowIdx, int colIdx)
      Select Cell by row and column positions
      Parameters:
      rowIdx - row position
      colIdx - column position
      Returns:
      Object for cell value (String, Float, Double)
    • getRowsByPosition

      public DataFrame getRowsByPosition(int... rowIndices)
      Select certains rows position
      Parameters:
      rowIndices - Basic Integer Array (int[]) for row positions
      Returns:
      New Dataframe with only the selected data
    • getByPositions

      public DataFrame getByPositions(int[] rowIndices, int[] colIndices)
      Select certains rows and columns by position
      Parameters:
      rowIndices - Basic Integer Array (int[]) for row positions
      colIndices - Basic Integer Array (int[]) for column positions
      Returns:
      New Dataframe with only the selected data
    • select

      public com.fahmatrix.Helpers.DataSelector select()
      Select using builder pattern
      use like that example
      select().rows(new int[]{1,2,3}).columns(new int[]{1,2,3}).get()
      or
      select().rows(new String[]{"row1","row2","row3"}).columns(new String[]{"column1","column2","column3"}).get()
      Returns:
      Selection Builder Object
    • print

      public void print()
      Pretty Print in System Console
    • describe

      public void describe()
      Pretty Print Data Summary in System Console
    • readCSV

      public DataFrame readCSV(String filePath)
      Read , Parse and save the CSV file
      Make sure the file is found before calling. And it has a proper CSV/TSV format
      All data are saved in the same object no need to create a new one

      Note: it replace any old data

      Parameters:
      filePath - CSV file path
      Returns:
      the same object after saving data (this) if successful
    • readXlsx

      public DataFrame readXlsx(String filePath)
      Read , Parse and save the Microsoft Excel SpreadSheet xlsx file
      Make sure the file is found before calling.
      All data are saved in the same object no need to create a new one

      Note: it replace any old data

      Parameters:
      filePath - xlsx file path
      Returns:
      the same object after saving data (this) if successful