Package fr.project.lib
Interface IDataFrame
- All Known Implementing Classes:
DataFrame
Interface defining a tabular data structure with labeled columns and rows,
providing functionality similar to pandas DataFrame in Python.
The DataFrame stores data in a 2D grid with the following characteristics:
- Columns have names and inferred/declared types
- Rows can optionally have labels
- Supports heterogeneous data (mixed types across columns)
- Provides flexible data access and statistical operations
-
Method Summary
Modifier and TypeMethodDescriptionget(int... columnIndices) Gets a subset DataFrame containing only the specified columns by index.Gets a subset DataFrame containing only the specified columns.Flexible element accessor supporting multiple retrieval patterns.booleangetEmpty()Checks if the DataFrame contains no data.intgetNDim()Gets the number of dimensions of the DataFrame.int[]getShape()Gets the dimensions of the DataFrame.intgetSize()Gets the total number of data cells in the DataFrame.iterator()Returns an iterator over the column labels of the DataFrame.floatFinds the maximum value in a numeric column.floatCalculates the arithmetic mean of a numeric column.floatFinds the minimum value in a numeric column.Removes and returns a column from the DataFrame.toCSV()Generates CSV representation of the DataFrame.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getEmpty
boolean getEmpty()Checks if the DataFrame contains no data.- Returns:
- true if the DataFrame has no rows or columns, false otherwise
- Throws:
IllegalStateException- if the operation cannot be completed
-
iterator
Returns an iterator over the column labels of the DataFrame.- Specified by:
iteratorin interfaceIterable<String>- Returns:
- Iterator of column names in their natural order
- Throws:
IllegalStateException- if the DataFrame is empty
-
getSize
int getSize()Gets the total number of data cells in the DataFrame.- Returns:
- Calculated as rows × columns
- Throws:
IllegalStateException- if the DataFrame is empty
-
getShape
int[] getShape()Gets the dimensions of the DataFrame.- Returns:
- 2-element array in format [rowCount, columnCount]
- Throws:
IllegalStateException- if the DataFrame is empty
-
getNDim
int getNDim()Gets the number of dimensions of the DataFrame.- Returns:
- Always returns 2 (rows and columns) for 2D structure
-
pop
Removes and returns a column from the DataFrame.- Parameters:
columnName- Name of the column to remove- Returns:
- List containing all values from the removed column in row order
- Throws:
IllegalStateException- if the DataFrame is emptyIllegalArgumentException- if the column doesn't exist
-
get
Gets a subset DataFrame containing only the specified columns.- Parameters:
columnNames- Names of columns to include in the subset- Returns:
- New DataFrame containing only the specified columns
- Throws:
IllegalStateException- if the DataFrame is emptyIllegalArgumentException- if any column name doesn't existNullPointerException- if columnNames is null
-
get
Gets a subset DataFrame containing only the specified columns by index.- Parameters:
columnIndices- 0-based indices of columns to include- Returns:
- New DataFrame containing only the specified columns
- Throws:
IllegalStateException- if the DataFrame is emptyIndexOutOfBoundsException- if any index is invalidNullPointerException- if columnIndices is null
-
getElem
Flexible element accessor supporting multiple retrieval patterns.Access Patterns:
- Single Element:
getElem(rowIndex, columnName) - Full Row:
getElem(rowIndex, null)→ returns Object[] - Full Column:
getElem(null, columnName)→ returns Object[]
- Parameters:
rowSpec- Can be:- Integer (0-based row index)
- String (row label if available)
- null (all rows)
columnSpec- Can be:- Integer (0-based column index)
- String (column name)
- null (all columns)
- Returns:
- Requested data in appropriate format
- Throws:
IllegalStateException- if DataFrame is emptyIllegalArgumentException- if:- Both specifiers are null
- Invalid specifier types
- Label not found
IndexOutOfBoundsException- if numeric indices are invalid
- Single Element:
-
Mean
Calculates the arithmetic mean of a numeric column.- Parameters:
columnName- Name of the column to calculate- Returns:
- Mean value as float
- Throws:
IllegalStateException- if DataFrame is emptyIllegalArgumentException- if:- Column doesn't exist
- Column is not numeric (Integer/Float)
- Column contains only null values
-
Max
Finds the maximum value in a numeric column.- Parameters:
columnName- Name of the column to analyze- Returns:
- Maximum value as float
- Throws:
IllegalStateException- if DataFrame is emptyIllegalArgumentException- if:- Column doesn't exist
- Column is not numeric (Integer/Float)
- Column contains only null values
-
Min
Finds the minimum value in a numeric column.- Parameters:
columnName- Name of the column to analyze- Returns:
- Minimum value as float
- Throws:
IllegalStateException- if DataFrame is emptyIllegalArgumentException- if:- Column doesn't exist
- Column is not numeric (Integer/Float)
- Column contains only null values
-
toCSV
String toCSV()Generates CSV representation of the DataFrame.- Returns:
- String containing CSV data with:
- First line: column headers
- Subsequent lines: data rows
- Proper escaping of special characters
- Throws:
IllegalStateException- if DataFrame is empty
-