1212* limitations under the License.
1313* ==========================================================================
1414*/
15- import { toCSVBrowser , toExcelBrowser , toJSONBrowser } from "../io/browser" ;
16- import { toCSVNode , toExcelNode , toJSONNode } from "../io/node" ;
1715import dummyEncode from "../transformers/encoders/dummy.encoder" ;
1816import { variance , std , median , mode , mean } from 'mathjs' ;
1917import tensorflow from '../shared/tensorflowlib'
@@ -22,7 +20,6 @@ import { _genericMathOp } from "./math.ops";
2220import Groupby from '../aggregators/groupby' ;
2321import ErrorThrower from "../shared/errors"
2422import { _iloc , _loc } from "./indexing" ;
25- import { PlotlyLib } from "../plotting" ;
2623import Utils from "../shared/utils"
2724import NDframe from "./generic" ;
2825import { table } from "table" ;
@@ -32,12 +29,6 @@ import {
3229 ArrayType2D ,
3330 DataFrameInterface ,
3431 BaseDataOptionType ,
35- CsvOutputOptionsBrowser ,
36- ExcelOutputOptionsBrowser ,
37- JsonOutputOptionsBrowser ,
38- CsvOutputOptionsNode ,
39- ExcelOutputOptionsNode ,
40- JsonOutputOptionsNode
4132} from "../shared/types" ;
4233
4334const utils = new Utils ( ) ;
@@ -3368,172 +3359,6 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
33683359
33693360 }
33703361
3371- /**
3372- * Exposes functions for creating charts from a DataFrame.
3373- * Charts are created using the Plotly.js library, so all Plotly's configuration parameters are available.
3374- * @param divId name of the HTML Div to render the chart in.
3375- */
3376- plot ( divId : string ) {
3377- //TODO: Add support for check plot library to use. So we can support other plot library like d3, vega, etc
3378- if ( utils . isBrowserEnv ( ) ) {
3379- const plt = new PlotlyLib ( this , divId ) ;
3380- return plt ;
3381- } else {
3382- throw new Error ( "Not supported in NodeJS" ) ;
3383- }
3384- }
3385-
3386- /**
3387- * Converts a DataFrame to CSV.
3388- * @param options Configuration object. Supports the following options:
3389- * - `filePath`: Local file path to write the CSV file. If not specified, the CSV will be returned as a string. Option is only available in NodeJS.
3390- * - `fileName`: Name of the CSV file. Defaults to `data.csv`. Option is only available in Browser.
3391- * - `download`: If true, the CSV will be downloaded. Defaults to false. Option is only available in Browser.
3392- * - `header`: Boolean indicating whether to include a header row in the CSV file.
3393- * - `sep`: Character to be used as a separator in the CSV file.
3394- *
3395- * @example
3396- * ```
3397- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3398- * const csv = df.toCSV()
3399- * console.log(csv)
3400- * //output
3401- * "A","B"
3402- * 1,2
3403- * 3,4
3404- * ```
3405- *
3406- * @example
3407- * ```
3408- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3409- * const csv = df.toCSV({ header: false })
3410- * console.log(csv)
3411- * //output
3412- * 1,2
3413- * 3,4
3414- * ```
3415- *
3416- * @example
3417- * ```
3418- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3419- * const csv = df.toCSV({ sep: ';' })
3420- * console.log(csv)
3421- * //output
3422- * "A";"B"
3423- * 1;2
3424- * 3;4
3425- * ```
3426- *
3427- * @example
3428- * ```
3429- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3430- * df.toCSV({ filePath: './data.csv' }) //write to local file in NodeJS
3431- * ```
3432- *
3433- * @example
3434- * ```
3435- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3436- * df.toCSV({ fileName: 'data.csv', download: true }) //Downloads file in Browser
3437- * ```
3438- *
3439- */
3440- toCSV ( options ?: CsvOutputOptionsBrowser | CsvOutputOptionsNode ) : string
3441- toCSV ( options ?: CsvOutputOptionsBrowser | CsvOutputOptionsNode ) : string | void {
3442- if ( utils . isBrowserEnv ( ) ) {
3443- return toCSVBrowser ( this , options as CsvOutputOptionsBrowser )
3444- } else {
3445- return toCSVNode ( this , options as CsvOutputOptionsNode )
3446- }
3447- }
3448-
3449- /**
3450- * Converts a DataFrame to JSON.
3451- * @param options Configuration object. Supported options:
3452- * - `filePath`: The file path to write the JSON to. If not specified, the JSON object is returned. Option is only available in NodeJS.
3453- * - `fileName`: The name of the JSON file. Defaults to `data.json`. Option is only available in Browser.
3454- * - `download`: If true, the JSON will be downloaded. Defaults to false. Option is only available in Browser.
3455- * - `format`: The format of the JSON. Supported values are `'column'` and `'row'`. Defaults to `'column'`.
3456- *
3457- * @example
3458- * ```
3459- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3460- * const json = df.toJSON()
3461- * ```
3462- *
3463- * @example
3464- * ```
3465- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3466- * const json = df.toJSON({ format: 'row' })
3467- * console.log(json)
3468- * //output
3469- * [{"A":1,"B":2},{"A":3,"B":4}]
3470- * ```
3471- *
3472- * @example
3473- * ```
3474- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3475- * const json = df.toJSON({ format: "column" })
3476- * console.log(json)
3477- * //output
3478- * {"A":[1,3],"B":[2,4]}
3479- * ```
3480- *
3481- * @example
3482- * ```
3483- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3484- * df.toJSON({ filePath: './data.json' }) // downloads to local file system as data.json in NodeJS
3485- * ```
3486- *
3487- * @example
3488- * ```
3489- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3490- * df.toJSON({ fileName: 'data.json', download: true }) // downloads file browser
3491- * ```
3492- */
3493- toJSON ( options ?: JsonOutputOptionsBrowser | JsonOutputOptionsNode ) : object
3494- toJSON ( options ?: JsonOutputOptionsBrowser | JsonOutputOptionsNode ) : object | void {
3495- if ( utils . isBrowserEnv ( ) ) {
3496- return toJSONBrowser ( this , options as JsonOutputOptionsBrowser )
3497- } else {
3498- return toJSONNode ( this , options as JsonOutputOptionsNode )
3499- }
3500- }
3501-
3502-
3503- /**
3504- * Converts a DataFrame to Excel file format.
3505- * @param options Configuration object. Supported options:
3506- * - `sheetName`: The sheet name to be written to. Defaults to `'Sheet1'`.
3507- * - `filePath`: The filePath to be written to. Defaults to `'./output.xlsx'`. Option is only available in NodeJs
3508- * - `fileName`: The fileName to be written to. Defaults to `'output.xlsx'`. Option is only available in Browser
3509- *
3510- * @example
3511- * ```
3512- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3513- * df.toExcel({ filePath: './output.xlsx' }) // writes to local file system as output.xlsx in NodeJS
3514- * ```
3515- *
3516- * @example
3517- * ```
3518- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3519- * df.toExcel({ fileName: 'output.xlsx', download: true }) // downloads file browser
3520- * ```
3521- *
3522- * @example
3523- * ```
3524- * const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3525- * df.toExcel({ sheetName: 'Sheet2' }) // writes to Sheet2 in Excel
3526- * ```
3527- *
3528- */
3529- toExcel ( options ?: ExcelOutputOptionsBrowser | ExcelOutputOptionsNode ) : void {
3530- if ( utils . isBrowserEnv ( ) ) {
3531- toExcelBrowser ( this , options as ExcelOutputOptionsBrowser )
3532- } else {
3533- return toExcelNode ( this , options as ExcelOutputOptionsNode )
3534- }
3535- }
3536-
35373362 /**
35383363 * Access a single value for a row/column pair by integer position.
35393364 * Similar to {@link iloc}, in that both provide integer-based lookups.
0 commit comments