@@ -130,69 +130,62 @@ Output in Browser:
130130### Example usage in Nodejs
131131
132132``` javascript
133+ const dfd = require (" danfojs-node" );
133134
134- const dfd = require (" danfojs-node" )
135+ const file_url =
136+ " https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv" ;
137+ dfd
138+ .readCSV (file_url)
139+ .then ((df ) => {
140+ // prints the first five columns
141+ df .head ().print ();
135142
136- const file_url = " https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv"
137- dfd .readCSV (file_url)
138- .then (df => {
139- // prints the first five columns
140- df .head ().print ()
143+ // Calculate descriptive statistics for all numerical columns
144+ df .describe ().print ();
141145
142- // Calculate descriptive statistics for all numerical columns
143- df . describe (). print ()
146+ // prints the shape of the data
147+ console . log ( df . shape );
144148
145- // prints the shape of the data
146- console .log (df .shape );
149+ // prints all column names
150+ console .log (df .columns );
147151
148- // prints all column names
149- console . log ( df .columns );
152+ // //prints the inferred dtypes of each column
153+ df .ctypes . print ( );
150154
151- // //prints the inferred dtypes of each column
152- df . ctypes . print ()
155+ // selecting a column by subsetting
156+ df[ " Name " ]. print ();
153157
154- // selecting a column by subsetting
155- df[' Name' ].print ()
158+ // drop columns by names
159+ let cols_2_remove = [" Age" , " Pclass" ];
160+ let df_drop = df .drop ({ columns: cols_2_remove, axis: 1 });
161+ df_drop .print ();
156162
157- // drop columns by names
158- cols_2_remove = [' Age' , ' Pclass' ]
159- df_drop = df .drop ({ columns: cols_2_remove, axis: 1 })
160- df_drop .print ()
163+ // select columns by dtypes
164+ let str_cols = df_drop .selectDtypes ([" string" ]);
165+ let num_cols = df_drop .selectDtypes ([" int32" , " float32" ]);
166+ str_cols .print ();
167+ num_cols .print ();
161168
169+ // add new column to Dataframe
162170
163- // select columns by dtypes
164- let str_cols = df_drop .selectDtypes ([" string" ])
165- let num_cols = df_drop .selectDtypes ([" int32" , " float32" ])
166- str_cols .print ()
167- num_cols .print ()
171+ let new_vals = df[" Fare" ].round (1 );
172+ df_drop .addColumn (" fare_round" , new_vals, { inplace: true });
173+ df_drop .print ();
168174
169- // select columns by dtypes
170- let str_cols = df_drop .select_dtypes ([" string" ])
171- let num_cols = df_drop .select_dtypes ([" int32" , " float32" ])
172- str_cols .print ()
173- num_cols .print ()
175+ df_drop[" fare_round" ].round (2 ).print (5 );
174176
175- // add new column to Dataframe
177+ // prints the number of occurence each value in the column
178+ df_drop[" Survived" ].valueCounts ().print ();
176179
177- let new_vals = df[' Fare' ].round (1 )
178- df_drop .addColumn (" fare_round" , new_vals, { inplace: true })
179- df_drop .print ()
180-
181- df_drop[' fare_round' ].round (2 ).print (5 )
182-
183- // prints the number of occurence each value in the column
184- df_drop[' Survived' ].valueCounts ().print ()
185-
186- // print the last ten elementa of a DataFrame
187- df_drop .tail (10 ).print ()
188-
189- // prints the number of missing values in a DataFrame
190- df_drop .isNa ().sum ().print ()
191-
192- }).catch (err => {
193- console .log (err);
194- })
180+ // print the last ten elementa of a DataFrame
181+ df_drop .tail (10 ).print ();
195182
183+ // prints the number of missing values in a DataFrame
184+ df_drop .isNa ().sum ().print ();
185+ })
186+ .catch ((err ) => {
187+ console .log (err);
188+ });
196189
197190```
198191Output in Node Console:
0 commit comments