Package fr.project.lib
Class DataFrame
java.lang.Object
fr.project.lib.DataFrame
- All Implemented Interfaces:
IDataFrame,Iterable<String>
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 -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget(int... colIndices) Gets subset DataFrame containing specified columns (by index)Gets subset DataFrame containing specified columns (by name)Single element/row/column accessbooleangetEmpty()Checks if DataFrame is emptyintgetNDim()Gets the number of dimensions of the DataFrame.int[]getShape()Gets dimensions of DataFrame [rows, columns]intgetSize()Gets total number of cells in DataFrameiterator()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 DataFrametoCSV()Generates CSV representation of the DataFrame.toString()Generates string representation of DataFrameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
col_types
-
-
Constructor Details
-
DataFrame
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:
getEmptyin interfaceIDataFrame- Returns:
- true if DataFrame contains no data
-
getSize
public int getSize()Gets total number of cells in DataFrame- Specified by:
getSizein interfaceIDataFrame- Returns:
- Count of all data cells
-
getShape
public int[] getShape()Gets dimensions of DataFrame [rows, columns]- Specified by:
getShapein interfaceIDataFrame- Returns:
- 2-element array with row and column counts
-
pop
Removes and returns a column from DataFrame- Specified by:
popin interfaceIDataFrame- 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
Gets subset DataFrame containing specified columns (by name)- Specified by:
getin interfaceIDataFrame- Parameters:
cols- Names of columns to include- Returns:
- New DataFrame with only specified columns
- Throws:
IllegalArgumentException- if any column not found
-
get
Gets subset DataFrame containing specified columns (by index)- Specified by:
getin interfaceIDataFrame- Parameters:
colIndices- Indices of columns to include- Returns:
- New DataFrame with only specified columns
- Throws:
IndexOutOfBoundsException- if any index is invalid
-
getElem
Single element/row/column access- Specified by:
getElemin interfaceIDataFrame- 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
Generates string representation of DataFrame -
iterator
Description copied from interface:IDataFrameReturns an iterator over the column labels of the DataFrame.- Specified by:
iteratorin interfaceIDataFrame- Specified by:
iteratorin interfaceIterable<String>- Returns:
- Iterator of column names in their natural order
-
Mean
Description copied from interface:IDataFrameCalculates the arithmetic mean of a numeric column.- Specified by:
Meanin interfaceIDataFrame- Parameters:
col- Name of the column to calculate- Returns:
- Mean value as float
-
Max
Description copied from interface:IDataFrameFinds the maximum value in a numeric column.- Specified by:
Maxin interfaceIDataFrame- Parameters:
col- Name of the column to analyze- Returns:
- Maximum value as float
-
Min
Description copied from interface:IDataFrameFinds the minimum value in a numeric column.- Specified by:
Minin interfaceIDataFrame- Parameters:
col- Name of the column to analyze- Returns:
- Minimum value as float
-
getNDim
public int getNDim()Description copied from interface:IDataFrameGets the number of dimensions of the DataFrame.- Specified by:
getNDimin interfaceIDataFrame- Returns:
- Always returns 2 (rows and columns) for 2D structure
-
toCSV
Description copied from interface:IDataFrameGenerates CSV representation of the DataFrame.- Specified by:
toCSVin interfaceIDataFrame- Returns:
- String containing CSV data with:
- First line: column headers
- Subsequent lines: data rows
- Proper escaping of special characters
-