Skip to main content

DataFrame

typedef struct {
double *data;
int numRows;
int numCols;
char **featureNames;
} DataFrame;

Represents a matrix with names for each column.

Data is stored as a row-major flattened array.

info

Added in version 0.0.0

Struct Members

  • double* dataFlattened array
  • int numRowsNumber of rows (samples)
  • int numColsNumber of columns (features) per row
  • char** featureNamesArray of column/feature names
  • DF_addColumnint
    Adds a single column/feature to an existing DataFrame.
    Params: DataFrame* df double* data char* name

  • DF_freevoid
    Frees all allocated memory by the DataFrame.
    Params: DataFrame* df

  • DF_fromArrayDataFrame*
    Creates a DataFrame with one feature from the given array.
    Params: double* data int numRows char* name

Example

#include <ml-in-c/datatypes/dataframe.h>

int main() {
// Create from array
double data[] = {1, 2, 3};
DataFrame *df = DF_fromArray(data, 3, "feature1");

// Add a column
double newData[] = {4, 5, 6};
DF_addColumn(df, newData, "feature2");

// Free array from memory
DF_free(df);

return 0;
}