Class DataFrame

java.lang.Object
fr.project.lib.DataFrame
All Implemented Interfaces:
IDataFrame, Iterable<String>

public class DataFrame extends Object implements IDataFrame
A Java implementation of a DataFrame similar to pandas' DataFrame. Stores tabular data with labeled columns and rows, supporting various data operations.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Supported input file formats
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Class<?>[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataFrame(String filename)
    Constructs DataFrame from a file
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int... colIndices)
    Gets subset DataFrame containing specified columns (by index)
    get(String... cols)
    Gets subset DataFrame containing specified columns (by name)
    getElem(Object rowSpec, Object colSpec)
    Single element/row/column access
    boolean
    Checks if DataFrame is empty
    int
    Gets the number of dimensions of the DataFrame.
    int[]
    Gets dimensions of DataFrame [rows, columns]
    int
    Gets total number of cells in DataFrame
    Returns an iterator over the column labels of the DataFrame.
    float
    Max(String col)
    Finds the maximum value in a numeric column.
    float
    Mean(String col)
    Calculates the arithmetic mean of a numeric column.
    float
    Min(String col)
    Finds the minimum value in a numeric column.
    Removes and returns a column from DataFrame
    Generates CSV representation of the DataFrame.
    Generates string representation of DataFrame

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • col_types

      public Class<?>[] col_types
  • Constructor Details

    • DataFrame

      public DataFrame(String filename) throws IOException
      Constructs DataFrame from a file
      Parameters:
      filename - Path to input file
      Throws:
      IOException - If file reading fails
  • Method Details

    • getEmpty

      public boolean getEmpty()
      Checks if DataFrame is empty
      Specified by:
      getEmpty in interface IDataFrame
      Returns:
      true if DataFrame contains no data
    • getSize

      public int getSize()
      Gets total number of cells in DataFrame
      Specified by:
      getSize in interface IDataFrame
      Returns:
      Count of all data cells
    • getShape

      public int[] getShape()
      Gets dimensions of DataFrame [rows, columns]
      Specified by:
      getShape in interface IDataFrame
      Returns:
      2-element array with row and column counts
    • pop

      public List<Object> pop(String s)
      Removes and returns a column from DataFrame
      Specified by:
      pop in interface IDataFrame
      Parameters:
      s - Name of column to remove
      Returns:
      List of values from the removed column
      Throws:
      IllegalArgumentException - if column not found or DataFrame is empty
    • get

      public IDataFrame get(String... cols)
      Gets subset DataFrame containing specified columns (by name)
      Specified by:
      get in interface IDataFrame
      Parameters:
      cols - Names of columns to include
      Returns:
      New DataFrame with only specified columns
      Throws:
      IllegalArgumentException - if any column not found
    • get

      public IDataFrame get(int... colIndices)
      Gets subset DataFrame containing specified columns (by index)
      Specified by:
      get in interface IDataFrame
      Parameters:
      colIndices - Indices of columns to include
      Returns:
      New DataFrame with only specified columns
      Throws:
      IndexOutOfBoundsException - if any index is invalid
    • getElem

      public Object getElem(Object rowSpec, Object colSpec)
      Single element/row/column access
      Specified by:
      getElem in interface IDataFrame
      Parameters:
      rowSpec - Can be:
      • Integer (0-based row index)
      • String (row label if available)
      • null (all rows)
      colSpec - Can be:
      • Integer (0-based column index)
      • String (column name)
      • null (all columns)
      Returns:
      Requested data in appropriate format
    • toString

      public String toString()
      Generates string representation of DataFrame
      Overrides:
      toString in class Object
      Returns:
      Formatted table showing data with labels
    • iterator

      public Iterator<String> iterator()
      Description copied from interface: IDataFrame
      Returns an iterator over the column labels of the DataFrame.
      Specified by:
      iterator in interface IDataFrame
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      Iterator of column names in their natural order
    • Mean

      public float Mean(String col)
      Description copied from interface: IDataFrame
      Calculates the arithmetic mean of a numeric column.
      Specified by:
      Mean in interface IDataFrame
      Parameters:
      col - Name of the column to calculate
      Returns:
      Mean value as float
    • Max

      public float Max(String col)
      Description copied from interface: IDataFrame
      Finds the maximum value in a numeric column.
      Specified by:
      Max in interface IDataFrame
      Parameters:
      col - Name of the column to analyze
      Returns:
      Maximum value as float
    • Min

      public float Min(String col)
      Description copied from interface: IDataFrame
      Finds the minimum value in a numeric column.
      Specified by:
      Min in interface IDataFrame
      Parameters:
      col - Name of the column to analyze
      Returns:
      Minimum value as float
    • getNDim

      public int getNDim()
      Description copied from interface: IDataFrame
      Gets the number of dimensions of the DataFrame.
      Specified by:
      getNDim in interface IDataFrame
      Returns:
      Always returns 2 (rows and columns) for 2D structure
    • toCSV

      public String toCSV()
      Description copied from interface: IDataFrame
      Generates CSV representation of the DataFrame.
      Specified by:
      toCSV in interface IDataFrame
      Returns:
      String containing CSV data with:
      • First line: column headers
      • Subsequent lines: data rows
      • Proper escaping of special characters