.______ ___ .__ __. _______ ___ _______. __ .__ __. ______
| _ \ / \ | \ | | | \ / \ / | | | | \ | | / |
| |_) | / ^ \ | \| | | .--. | / ^ \ | (----` | | | \| | | ,----'
| ___/ / /_\ \ | . ` | | | | | / /_\ \ \ \ | | | . ` | | |
| | / _____ \ | |\ | | '--' | / _____ \ .----) | | | | |\ | | `----.
| _| /__/ \__\ |__| \__| |_______/ /__/ \__\ |_______/ |__| |__| \__| \______|
This C program demonstrates some basic operations on a DataFrame. The program creates a DataFrame structure, adds rows to it, and performs operations such as printing the DataFrame, calculating summary statistics, and performing aggregation.
The code consists of the following components:
- Includes the necessary libraries for input/output and string handling.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
- Defines the
Row
structure to represent a single row of data in the DataFrame.
typedef struct {
char name[20];
int age;
char city[20];
char gender[10];
} Row;
- Defines the
DataFrame
structure to store rows and the number of rows.
typedef struct {
Row* rows;
int num_rows;
} DataFrame;
- Implements the
createDataFrame
function that creates a DataFrame with a given number of rows and initializes each row with default values.
DataFrame* createDataFrame(int num_rows) {
// Implementation details
return df;
}
- Implements the
freeDataFrame
function that frees the memory allocated for the DataFrame and its rows.
void freeDataFrame(DataFrame* df) {
// Implementation details
}
- Implements the
addRow
function that adds a new row to the DataFrame.
void addRow(DataFrame* df, const char* name, int age, const char* city, const char* gender) {
// Implementation details
}
- Implements the
printDataFrame
function that prints the contents of the DataFrame.
void printDataFrame(DataFrame* df) {
// Implementation details
}
- Implements the
calculateSummaryStatistics
function that calculates and prints summary statistics of the DataFrame.
void calculateSummaryStatistics(DataFrame* df) {
// Implementation details
}
- Implements the
performAggregation
function that performs aggregation on a specified column of the DataFrame.
void performAggregation(DataFrame* df, const char* column) {
// Implementation details
}
- The
main
function demonstrates the usage of DataFrame operations. It creates a DataFrame, adds rows, and performs operations like printing the DataFrame, calculating summary statistics, and performing aggregation.
int main() {
// Implementation details
return 0;
}
- Compile the program using a C compiler.
gcc dataframe_operations.c -o dataframe_operations
- Run the executable.
./dataframe_operations
The program generates the following output:
Name: John, Age: 25, City: New York, Gender: Male
Name: Alice, Age: 30, City: London, Gender: Female
Name: Bob, Age: 35, City: Paris, Gender: Male
Summary Statistics:
Total rows: 3
Minimum age: 25
Maximum age: 35
Average age: 30.00
Aggregation by gender:
Number of Males: 2
Number of Females: 1
Aggregation by city:
Number of Unique Cities: 3
The program frees the memory allocated for the DataFrame and its rows to avoid memory leaks.
This project is licensed under the MIT License.
Feel free to modify and use the code according to your needs.
Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements you would like to make.
This program was developed by Soumya Chakraborty as a demonstration of basic DataFrame operations in C.