@@ -88,7 +88,7 @@ See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
8888
8989 df .plot (" div2" ).table () // display csv as table
9090
91- new_df = df .set_index ({ key : " Date" }) // resets the index to Date column
91+ new_df = df .set_index ({ column : " Date" }) // resets the index to Date column
9292 new_df .plot (" div3" ).line ({ columns: [" AAPL.Open" , " AAPL.High" ] }) // makes a timeseries plot
9393
9494 }).catch (err => {
@@ -119,59 +119,60 @@ npm install danfojs-node
119119
120120const dfd = require (" danfojs-node" )
121121
122+ const file_url = " https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv"
123+ dfd .read_csv (file_url)
124+ .then (df => {
125+ // prints the first five columns
126+ df .head ().print ()
122127
123- dfd .read_csv (" https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv" )
124- .then (df => {
125- // prints the first five columns
126- df .head ().print ()
128+ // Calculate descriptive statistics for all numerical columns
129+ df .describe ().print ()
127130
128- // Calculate descriptive statistics for all numerical columns
129- df . describe (). print ()
131+ // prints the shape of the data
132+ console . log ( df . shape );
130133
131- // prints the shape of the data
132- console .log (df .shape );
134+ // prints all column names
135+ console .log (df .columns );
133136
134- // prints all column names
135- console . log ( df .column_names );
137+ // // prints the inferred dtypes of each column
138+ df .ctypes . print ()
136139
137- // prints the inferred dtypes of each column
138- df . ctypes .print ()
140+ // selecting a column by subsetting
141+ df[ ' Name ' ] .print ()
139142
140- // selecting a column by subsetting
141- df[' Name' ].print ()
143+ // drop columns by names
144+ cols_2_remove = [' Age' , ' Pclass' ]
145+ df_drop = df .drop ({ columns: cols_2_remove, axis: 1 })
146+ df_drop .print ()
142147
143- // drop columns by names
144- cols_2_remove = [' Age' , ' Pclass' ]
145- df_drop = df .drop ({ columns: cols_2_remove, axis: 1 })
146- df_drop .print ()
147148
149+ // select columns by dtypes
150+ let str_cols = df_drop .select_dtypes ([" string" ])
151+ let num_cols = df_drop .select_dtypes ([" int32" , " float32" ])
152+ str_cols .print ()
153+ num_cols .print ()
148154
149- // select columns by dtypes
150- let str_cols = df_drop .select_dtypes ([" string" ])
151- let num_cols = df_drop .select_dtypes ([" int32" , " float32" ])
152- str_cols .print ()
153- num_cols .print ()
154155
156+ // add new column to Dataframe
155157
156- // add new column to Dataframe
157- let new_vals = df[' Fare' ].round ().values
158- df_drop .addColumn ({ column: " fare_round" , value: new_vals})
159- df_drop .print ()
158+ let new_vals = df[' Fare' ].round (1 )
159+ df_drop .addColumn ({ column: " fare_round" , values: new_vals, inplace: true })
160+ df_drop .print ()
160161
161- df_drop[' fare_round' ].print (5 )
162+ df_drop[' fare_round' ]. round ( 2 ) .print (5 )
162163
163- // prints the number of occurence each value in the column
164- df_drop[' Survived' ].value_counts ().print ()
164+ // prints the number of occurence each value in the column
165+ df_drop[' Survived' ].value_counts ().print ()
165166
166- // print the last ten elementa of a DataFrame
167- df_drop .tail (10 ).print ()
167+ // print the last ten elementa of a DataFrame
168+ df_drop .tail (10 ).print ()
168169
169- // prints the number of missing values in a DataFrame
170- df_drop .isna ().sum ().print ()
170+ // prints the number of missing values in a DataFrame
171+ df_drop .isna ().sum ().print ()
171172
172- }).catch (err => {
173- console .log (err);
174- })
173+ }).catch (err => {
174+ console .log (err);
175+ })
175176
176177```
177178Output in Node Console:
0 commit comments