Package com.fahmatrix
Class DataFrame
java.lang.Object
com.fahmatrix.DataFrame
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, Ods, JSON
Export To CSV/TSV, xlsx, Ods, JSON
Reverse (transpose) data
Select Row/Column by Label or Position
Filter By String Opertions (contains, equal, equal ignore case, start with , end with, regex , not empty, custom String Predicate)
Current Features:
Select/Add column data
Print in System Console
Print data Summary
Import From CSV/TSV, xlsx, Ods, JSON
Export To CSV/TSV, xlsx, Ods, JSON
Reverse (transpose) data
Select Row/Column by Label or Position
Filter By String Opertions (contains, equal, equal ignore case, start with , end with, regex , not empty, custom String Predicate)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add column to the end of data tablevoid
describe()
Pretty Print Data Summary in System ConsolefilterByStringPredicate
(String columnName, Predicate<String> predicate) Filters rows based on a custom string predicatefilterContains
(String columnName, String substring) Filters rows where the specified column contains the given substringfilterEndsWith
(String columnName, String suffix) Filter rows where the specified column ends with the given suffixfilterEquals
(String columnName, String value) Filters rows where the specified column equals the given value (case-sensitive)filterEqualsIgnoreCase
(String columnName, String value) Filters rows where the specified column equals the given value (case-insensitive)filterNotEmpty
(String columnName) Filter rows where the specified column is not null and not emptyfilterRegex
(String columnName, String regex) Filter rows where the specified column matches the given regex patternfilterStartsWith
(String columnName, String prefix) Filter rows where the specified column starts with the given prefixgetByLabel
(String rowLabel, String colLabel) Select Cell by row and column namegetByLabels
(String[] rowLabels, String[] colLabels) Select certains rows and columns by name
these names are not Excel A1,B1 names.getByPosition
(int rowIdx, int colIdx) Select Cell by row and column positionsgetByPositions
(int[] rowIndices, int[] colIndices) Select certains rows and columns by positionreturn a new Series Object with data of only one columngetColumnsByLabel
(String... columnLabels) Select Columns by name
this method assumes you selected all rowsgetColumnsByPosition
(int... columnIndices) Select certains columns positiongetRowsByLabel
(String... rowLabels) Select Rows by name
this method assumes you selected all columnsgetRowsByPosition
(int... rowIndices) Select certains rows positionhead()
Return the first 5 rows as DataFrame Objecthead
(int n) Return the first n rows as DataFrame Objectvoid
print()
Pretty Print in System ConsoleRead , Parse and save the CSV file
Make sure the file is found before calling.Read , Parse and save the JSON file
Make sure the file is found before calling.Read , Parse and save ODS (OpenDocument Spreadsheet) file
Make sure the file is found before calling.Read , Parse and save the Microsoft Excel SpreadSheet xlsx file
Make sure the file is found before calling.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()tail()
Return the last 5 rows as DataFrame Objecttail
(int n) Return the last n rows as DataFrame ObjectReverse Rows and Columnsvoid
Exports data to a csv file
It useds default delimiter "," and hasQoutes is set to truevoid
Exports data to a csv file
void
Exports data to a JSON txt file
void
Exports data to an ODS (OpenDocument Spreadsheet) file
The data is in the default sheet with name "sheet1"void
Exports data to a Microsoft Excel SpreadSheet xlsx file
The data is in the default sheet with name "sheet1"
-
Constructor Details
-
DataFrame
public DataFrame()Constructor with empty indexes and columns -
DataFrame
Constructor with known indexes and empty columns- Parameters:
index
- Array of indexes
-
DataFrame
Constructor with known indexes and columns- Parameters:
index
- Array of indexescolumns
- Map of data where key is the column name and the value is Array of cells data
-
-
Method Details
-
addColumn
Add column to the end of data table- Parameters:
name
- index namedata
- column data (Array of cells data)
-
getColumn
return a new Series Object with data of only one column- Parameters:
name
- column name- Returns:
- Series data with index
-
getColumnsByLabel
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
Select certains columns position- Parameters:
columnIndices
- Basic Integer Array (int[]) for columns position- Returns:
- New Dataframe with only the selected datas
-
head
Return the first 5 rows as DataFrame Object- Returns:
- first 5 rows
-
head
Return the first n rows as DataFrame Object- Parameters:
n
- the max number of rows to return- Returns:
- rows
-
tail
Return the last 5 rows as DataFrame Object- Returns:
- last 5 rows
-
tail
Return the last n rows as DataFrame Object- Parameters:
n
- the max number of rows to return- Returns:
- rows
-
transpose
Reverse Rows and Columns- Returns:
- new DataFrame with transposed data
-
getByLabel
Select Cell by row and column name- Parameters:
rowLabel
- row namecolLabel
- column name- Returns:
- Object for cell value (String, Float, Double)
-
getRowsByLabel
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
Select certains rows and columns by name
these names are not Excel A1,B1 names.- Parameters:
rowLabels
- Basic String Array (String[]) for row namescolLabels
- Basic String Array (String[]) for column names- Returns:
- New Dataframe with only the selected data
-
getByPosition
Select Cell by row and column positions- Parameters:
rowIdx
- row positioncolIdx
- column position- Returns:
- Object for cell value (String, Float, Double)
-
getRowsByPosition
Select certains rows position- Parameters:
rowIndices
- Basic Integer Array (int[]) for row positions- Returns:
- New Dataframe with only the selected data
-
getByPositions
Select certains rows and columns by position- Parameters:
rowIndices
- Basic Integer Array (int[]) for row positionscolIndices
- Basic Integer Array (int[]) for column positions- Returns:
- New Dataframe with only the selected data
-
filterContains
Filters rows where the specified column contains the given substring- Parameters:
columnName
- the name of the column to filtersubstring
- the substring to search for- Returns:
- New Dataframe with only the selected data
-
filterEquals
Filters rows where the specified column equals the given value (case-sensitive)- Parameters:
columnName
- the name of the column to filtervalue
- the value to match exactly- Returns:
- New Dataframe with only the selected data
-
filterEqualsIgnoreCase
Filters rows where the specified column equals the given value (case-insensitive)- Parameters:
columnName
- the name of the column to filtervalue
- the value to match (ignoring case)- Returns:
- New Dataframe with only the selected data
-
filterByStringPredicate
Filters rows based on a custom string predicate- Parameters:
columnName
- the name of the column to filterpredicate
- a function that takes a string and returns true if the row should be included- Returns:
- New Dataframe with only the selected data
-
filterStartsWith
Filter rows where the specified column starts with the given prefix- Parameters:
columnName
- the name of the column to filterprefix
- the prefix to match- Returns:
- New Dataframe with only the selected data
-
filterEndsWith
Filter rows where the specified column ends with the given suffix- Parameters:
columnName
- the name of the column to filtersuffix
- the suffix to match- Returns:
- New Dataframe with only the selected data
-
filterRegex
Filter rows where the specified column matches the given regex pattern- Parameters:
columnName
- the name of the column to filterregex
- the regular expression pattern to match- Returns:
- New Dataframe with only the selected data
-
filterNotEmpty
Filter rows where the specified column is not null and not empty- Parameters:
columnName
- the name of the column to filter- 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
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
-
writeCSV
Exports data to a csv file
It useds default delimiter "," and hasQoutes is set to true- Parameters:
filePath
- full file path to save ex: ".\\examples\\exampleFiles\\customers-edited.csv"
-
writeCSV
Exports data to a csv file
- Parameters:
filePath
- full file path to save ex: ".\\examples\\exampleFiles\\customers-edited.csv"delimiter
- the csv value delimter ex: ',' or ';' or '|'hasQuotes
- either wrap the values within qoutes or not
-
readXlsx
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
-
writeXlsx
Exports data to a Microsoft Excel SpreadSheet xlsx file
The data is in the default sheet with name "sheet1"- Parameters:
filePath
- full file path to save ex: ".\\examples\\exampleFiles\\small_data.xlsx"
-
readOds
Read , Parse and save ODS (OpenDocument Spreadsheet) 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
- ods file path- Returns:
- the same object after saving data (this) if successful
-
writeOds
Exports data to an ODS (OpenDocument Spreadsheet) file
The data is in the default sheet with name "sheet1"- Parameters:
filePath
- full file path to save ex: ".\\examples\\exampleFiles\\small_data.ods"
-
readJson
Read , Parse and save the JSON file
Make sure the file is found before calling. And it has a proper JSON format
All data are saved in the same object no need to create a new one
Note: it replace any old data
Note: it supports simple JSON data. (no nesting)
example of JSON data. [ {"age": 25, "name": "Alice"}, {"age": 30, "name": "Bob"}, {"age": 35, "name": "Charlie"} ]- Parameters:
filePath
- JSON file path- Returns:
- the same object after saving data (this) if successful
-
writeJson
Exports data to a JSON txt file
- Parameters:
filePath
- full file path to save ex: ".\\examples\\exampleFiles\\small_data.json"
-