@@ -86,7 +86,7 @@ To use Danfo.js via script tags, copy and paste the CDN below to the body of you
8686
8787 df .plot (" div2" ).table () // display csv as table
8888
89- new_df = df .set_index ({ key : " Date" }) // resets the index to Date column
89+ new_df = df .set_index ({ column : " Date" }) // resets the index to Date column
9090 new_df .plot (" div3" ).line ({ columns: [" AAPL.Open" , " AAPL.High" ] }) // makes a timeseries plot
9191
9292 }).catch (err => {
@@ -117,59 +117,61 @@ npm install danfojs-node
117117
118118const dfd = require (" danfojs-node" )
119119
120+ const file_url = " https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv"
121+ dfd .read_csv (file_url)
122+ .then (df => {
123+ // prints the first five columns
124+ df .head ().print ()
120125
121- dfd .read_csv (" https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv" )
122- .then (df => {
123- // prints the first five columns
124- df .head ().print ()
126+ // Calculate descriptive statistics for all numerical columns
127+ df .describe ().print ()
125128
126- // Calculate descriptive statistics for all numerical columns
127- df . describe (). print ()
129+ // prints the shape of the data
130+ console . log ( df . shape );
128131
129- // prints the shape of the data
130- console .log (df .shape );
132+ // prints all column names
133+ console .log (df .columns );
131134
132- // prints all column names
133- console . log ( df .column_names );
135+ // // prints the inferred dtypes of each column
136+ df .ctypes . print ()
134137
135- // prints the inferred dtypes of each column
136- df . ctypes .print ()
138+ // selecting a column by subsetting
139+ df[ ' Name ' ] .print ()
137140
138- // selecting a column by subsetting
139- df[' Name' ].print ()
141+ // drop columns by names
142+ cols_2_remove = [' Age' , ' Pclass' ]
143+ df_drop = df .drop ({ columns: cols_2_remove, axis: 1 })
144+ df_drop .print ()
140145
141- // drop columns by names
142- cols_2_remove = [' Age' , ' Pclass' ]
143- df_drop = df .drop ({ columns: cols_2_remove, axis: 1 })
144- df_drop .print ()
145146
147+ // select columns by dtypes
148+ let str_cols = df_drop .select_dtypes ([" string" ])
149+ let num_cols = df_drop .select_dtypes ([" int32" , " float32" ])
150+ str_cols .print ()
151+ num_cols .print ()
146152
147- // select columns by dtypes
148- let str_cols = df_drop .select_dtypes ([" string" ])
149- let num_cols = df_drop .select_dtypes ([" int32" , " float32" ])
150- str_cols .print ()
151- num_cols .print ()
152153
154+ // add new column to Dataframe
153155
154- // add new column to Dataframe
155- let new_vals = df[' Fare' ].round ().values
156- df_drop .addColumn ({ column: " fare_round" , value: new_vals})
157- df_drop .print ()
156+ let new_vals = df[' Fare' ].round (1 )
157+ df_drop .addColumn ({ column: " fare_round" , values: new_vals, inplace: true })
158+ df_drop .print ()
158159
159- df_drop[' fare_round' ].print (5 )
160+ df_drop[' fare_round' ]. round ( 2 ) .print (5 )
160161
161- // prints the number of occurence each value in the column
162- df_drop[' Survived' ].value_counts ().print ()
162+ // prints the number of occurence each value in the column
163+ df_drop[' Survived' ].value_counts ().print ()
163164
164- // print the last ten elementa of a DataFrame
165- df_drop .tail (10 ).print ()
165+ // print the last ten elementa of a DataFrame
166+ df_drop .tail (10 ).print ()
166167
167- // prints the number of missing values in a DataFrame
168- df_drop .isna ().sum ().print ()
168+ // prints the number of missing values in a DataFrame
169+ df_drop .isna ().sum ().print ()
170+
171+ }).catch (err => {
172+ console .log (err);
173+ })
169174
170- }).catch (err => {
171- console .log (err);
172- })
173175
174176```
175177Output in Node Console:
0 commit comments