1313* ==========================================================================
1414*/
1515import BaseDataFrame from "../../../danfojs-base/core/frame"
16- import { PlotlyLib } from "../../../danfojs-base/plotting" ;
17- import { toCSVBrowser , toJSONBrowser , toExcelBrowser } from "../../../danfojs-base/io/browser" ;
18- import {
19- BaseDataOptionType ,
20- DataFrameInterface ,
21- CsvOutputOptionsBrowser ,
22- JsonOutputOptionsBrowser ,
23- ExcelOutputOptionsBrowser ,
24- IPlotlyLib
25- } from "../../../danfojs-base/shared/types" ;
26-
27- type ExtendedDataFrameInterface = DataFrameInterface & {
28- plot ( divId : string ) : IPlotlyLib
29- toCSV ( options ?: CsvOutputOptionsBrowser ) : string | void
30- toJSON ( options ?: JsonOutputOptionsBrowser ) : object | void
31- toExcel ( options ?: ExcelOutputOptionsBrowser ) : void
32- }
16+ import { BaseDataOptionType } from "../../../danfojs-base/shared/types" ;
3317
3418/**
3519 * Two-dimensional ndarray with axis labels.
@@ -41,145 +25,9 @@ type ExtendedDataFrameInterface = DataFrameInterface & {
4125 * @param options.dtypes Array of data types for each the column. If not specified, dtypes are/is inferred.
4226 * @param options.config General configuration object for extending or setting NDframe behavior.
4327 */
44- export default class DataFrame extends BaseDataFrame implements ExtendedDataFrameInterface {
28+ export default class DataFrame extends BaseDataFrame {
4529 [ key : string ] : any
4630 constructor ( data ?: any , options : BaseDataOptionType = { } ) {
4731 super ( data , options )
4832 }
49-
50- /**
51- * Exposes functions for creating charts from a DataFrame.
52- * Charts are created using the Plotly.js library, so all Plotly's configuration parameters are available.
53- * @param divId name of the HTML Div to render the chart in.
54- */
55- plot ( divId : string ) {
56- const plt = new PlotlyLib ( this , divId ) ;
57- return plt ;
58- }
59-
60- /**
61- * Converts a DataFrame to CSV.
62- * @param options Configuration object. Supports the following options:
63- * - `fileName`: Name of the CSV file. Defaults to `data.csv`. Option is only available in Browser.
64- * - `download`: If true, the CSV will be downloaded. Defaults to false. Option is only available in Browser.
65- * - `header`: Boolean indicating whether to include a header row in the CSV file.
66- * - `sep`: Character to be used as a separator in the CSV file.
67- *
68- * @example
69- * ```
70- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
71- * const csv = df.toCSV()
72- * console.log(csv)
73- * //output
74- * "A","B"
75- * 1,2
76- * 3,4
77- * ```
78- *
79- * @example
80- * ```
81- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
82- * const csv = df.toCSV({ header: false })
83- * console.log(csv)
84- * //output
85- * 1,2
86- * 3,4
87- * ```
88- *
89- * @example
90- * ```
91- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
92- * const csv = df.toCSV({ sep: ';' })
93- * console.log(csv)
94- * //output
95- * "A";"B"
96- * 1;2
97- * 3;4
98- * ```
99- *
100- * @example
101- * ```
102- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
103- * df.toCSV({ fileName: 'data.csv', download: true }) //Downloads file in Browser
104- * ```
105- *
106- */
107- toCSV ( options ?: CsvOutputOptionsBrowser ) : string
108- toCSV ( options ?: CsvOutputOptionsBrowser ) : string | void {
109- return toCSVBrowser ( this , options )
110-
111- }
112-
113- /**
114- * Converts a DataFrame to JSON.
115- * @param options Configuration object. Supported options:
116- * - `fileName`: The name of the JSON file. Defaults to `data.json`. Option is only available in Browser.
117- * - `download`: If true, the JSON will be downloaded. Defaults to false. Option is only available in Browser.
118- * - `format`: The format of the JSON. Supported values are `'column'` and `'row'`. Defaults to `'column'`.
119- *
120- * @example
121- * ```
122- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
123- * const json = df.toJSON()
124- * ```
125- *
126- * @example
127- * ```
128- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
129- * const json = df.toJSON({ format: 'row' })
130- * console.log(json)
131- * //output
132- * [{"A":1,"B":2},{"A":3,"B":4}]
133- * ```
134- *
135- * @example
136- * ```
137- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
138- * const json = df.toJSON({ format: "column" })
139- * console.log(json)
140- * //output
141- * {"A":[1,3],"B":[2,4]}
142- * ```
143- *
144- * @example
145- * ```
146- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
147- * df.toJSON({ fileName: 'data.json', download: true }) // downloads file browser
148- * ```
149- */
150- toJSON ( options ?: JsonOutputOptionsBrowser ) : object
151- toJSON ( options ?: JsonOutputOptionsBrowser ) : object | void {
152- return toJSONBrowser ( this , options )
153- }
154-
155-
156- /**
157- * Converts a DataFrame to Excel file format.
158- * @param options Configuration object. Supported options:
159- * - `sheetName`: The sheet name to be written to. Defaults to `'Sheet1'`.
160- * - `filePath`: The filePath to be written to. Defaults to `'./output.xlsx'`. Option is only available in NodeJs
161- * - `fileName`: The fileName to be written to. Defaults to `'output.xlsx'`. Option is only available in Browser
162- *
163- * @example
164- * ```
165- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
166- * df.toExcel({ filePath: './output.xlsx' }) // writes to local file system as output.xlsx in NodeJS
167- * ```
168- *
169- * @example
170- * ```
171- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
172- * df.toExcel({ fileName: 'output.xlsx', download: true }) // downloads file browser
173- * ```
174- *
175- * @example
176- * ```
177- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
178- * df.toExcel({ sheetName: 'Sheet2' }) // writes to Sheet2 in Excel
179- * ```
180- *
181- */
182- toExcel ( options ?: ExcelOutputOptionsBrowser ) : void {
183- return toExcelBrowser ( this , options )
184- }
18533}
0 commit comments