JSPM

jpandas

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q35941F
  • License BSD-3-Clause

A lightweight JavaScript package for working with tabular data, inspired by pandas in Python.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jpandas) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    πŸ“Ÿ A lightweight JavaScript package for working with tabular data, inspired by pandas in Python..

    npm version DOWNLOADS

    jpandas

    • πŸ“¦ Easy creation of tabular data structures in JavaScript.
    • πŸ“¦ Provides a DataFrame class inspired by pandas in Python.
    • πŸ‘¨β€πŸ« Developed by Rajnish.

    Table of Contents

    Installation

    npm install jpandas
    
    or
    
    yarn add jpandas

    Usage

    Here’s a quick example of how to use the DataFrame Library in your project:

    import DataFrame from 'jpandas';
    
    const data = [
        { Name: 'Ankit', Age: 23, University: 'BHU' },
        { Name: 'Aishwarya', Age: 21, University: 'JNU' }
    ];
    
    const df = new DataFrame(data);
    console.log(df.getRowCount()); // Outputs: 2

    Creating DataFrames

    From an Array

    You can create a DataFrame from a 2D array:

    const data = [
        [1, 4, 7],
        [2, 5, 8],
        [3, 6, 9]
    ];
    const df = new DataFrame(data);
    console.log(df.getRowCount()); // Outputs: 3

    From an Object

    You can also create a DataFrame from an object where keys are column names:

    const data = {
        Name: ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi'],
        Age: [23, 21, 22, 21],
        University: ['BHU', 'JNU', 'DU', 'BHU']
    };
    const df = new DataFrame(data);
    console.log(df.getValue(0, 'Name')); // Outputs: 'Ankit'

    From CSV String

    To create a DataFrame from a CSV string:

    const csvData = `Name,Age,University\nAnkit,23,BHU\nAishwarya,21,JNU`;
    const df = new DataFrame(csvData);
    console.log(df.getValue(1, 'Age')); // Outputs: 21

    From JSON String

    You can also create a DataFrame from a JSON string:

    const jsonString = `[{"Name": "Ankit", "Age": 23, "University": "BHU"}, {"Name": "Aishwarya", "Age": 21, "University": "JNU"}]`;
    const df = new DataFrame(JSON.parse(jsonString));
    console.log(df.getValue(1, 'University')); // Outputs: 'JNU'

    DataFrame Operations

    Group By

    Group your DataFrame by a specific column:

    const grouped = df.groupBy('University');
    console.log(Object.keys(grouped).length); // Outputs: number of unique universities

    Rename Columns

    You can rename columns easily:

    const renamedDf = df.rename({ a: 'x', b: 'y' });
    console.log(renamedDf.getColumns()); // Outputs: ['x', 'y', 'c']

    Transform DataFrame

    Transform your DataFrame using a custom function:

    const transformedDf = df.transform(row => ({
        FullName: row.Name,
        Age: row.Age + 1
    }));
    console.log(transformedDf.getValue(0, 'FullName')); // Outputs: 'Ankit'

    Calculate Mean

    Calculate the mean of a numeric column:

    const meanAge = df.mean('Age');
    console.log(meanAge); // Outputs: average age

    Contributing

    License

    Contact

    GitHub @rajnish93 (follow) To stay up to date on free & open-source software

    LinkedIn @krajnishsingh (connect) On the LinkedIn profile