88#include <stdint.h>
99#include <stdio.h>
1010#include <stdlib.h>
11+ #include <string.h>
1112
1213#include "dataframe.h"
1314#include "debug.h"
@@ -24,12 +25,13 @@ bool filter_func(void *vl)
2425
2526void * apply_func (void * value )
2627{
27- int * new_value = malloc ( sizeof ( int ) );
28+ char * str = strdup (( char * ) value );
2829
29- if (new_value == NULL )
30+ if (str == NULL )
3031 return NULL ;
31- * new_value = * (int * )value * 2 ;
32- return new_value ;
32+ if (str [strlen (str ) - 1 ] == 'e' )
33+ str [strlen (str ) - 1 ] = '\0' ;
34+ return str ;
3335}
3436
3537static
@@ -56,14 +58,24 @@ void print_df(int rows, int col, void ***data, column_type_t type)
5658
5759int main (int ac , char * * av )
5860{
59- dataframe_t * src = df_read_csv (av [1 ], ";" );
60- dataframe_t * df = df_apply (src , "age" , apply_func );
61+ dataframe_t * src = df_read_csv (av [1 ], NULL );
62+ dataframe_t * int_df = df_apply (src , "amount" , apply_func );
63+ dataframe_t * dst = df_to_type (int_df , "amount" , INT );
64+ dataframe_t * df = df_sort (dst , "amount" , sort_func );
6165
6266 if (df == NULL )
6367 return 84 ;
6468 df_write_csv (df , "result.csv" );
6569 printf ("nb_columns= %d\n" , df -> nb_columns );
6670 printf ("nb_rows= %d\n" , df -> nb_rows );
71+ df_info (df );
72+ df_describe (df );
73+ df_shape (df );
74+ df_filter (df , "amount" , filter_func );
75+ df_head (df , 1 );
76+ df_tail (df , 1 );
77+ df_get_value (df , 0 , "amount" );
78+ df_get_values (df , "amount" );
6779#if defined(U_DEBUG_MODE )
6880 printf ("columns: " );
6981 for (int a = 0 ; a < df -> nb_columns ; a ++ )
@@ -78,5 +90,7 @@ int main(int ac, char **av)
7890 }
7991 df_free (src );
8092 df_free (df );
93+ df_free (int_df );
94+ df_free (dst );
8195 return 0 ;
8296}
0 commit comments