jspandas
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

JsPandas

JsPandas is a lightweight JavaScript library for data manipulation and analysis, inspired by the popular pandas library in Python. It provides flexible data structures and data analysis tools similar to pandas, enabling efficient data handling and manipulation in JavaScript.

Features

  • Read and write data from/to CSV, Excel, TSV, and JSON files
  • Data manipulation functions such as filtering, sorting, grouping, and aggregating
  • Apply functions to columns or rows
  • Iterate over rows with iterrows method
  • Descriptive statistics

Installation

You can install JsPandas using npm:

npm install jspandas

Usage

Creating a DataFrame

    const { Pandas } = require('jspandas');

    // Create some sample data
    const data = [
    { col1: 1, col2: 2, col3: 3 },
    { col1: 4, col2: 5, col3: 6 },
    { col1: 7, col2: 8, col3: 9 }
    ];

    // Create a DataFrame using the Pandas class
    const df = Pandas.DataFrame(data);
    console.log(df);

Reading and Writing Data

    const { Pandas } = require('jspandas');

    // Read data from CSV file
    const df = await Pandas.readCSV('data.csv');
    console.log(df);

    // Read data from Excel file
    const df = await Pandas.readExcel('data.xlsx', 'Sheet1');
    console.log(df);

    // Read data from TSV file
    const df = await Pandas.readTSV('data.tsv');
    console.log(df);

    // Read data from JSON file
    const df = await Pandas.readJSON('data.json');
    console.log(df);


    await df.toCSV('output.csv');

    // Write data to Excel file
    await df.toEXCEL('output.xlsx');

    // Write data to JSON file
    await df.toJSON('output.json');

Data Manipulation

const { Pandas } = require('jspandas');

// Create some sample data
const data = [
  { col1: 1, col2: 2, col3: 3 },
  { col1: 4, col2: 5, col3: 6 },
  { col1: 7, col2: 8, col3: 9 }
];

const df = Pandas.DataFrame(data);

// Filter rows
const filteredDf = df.filter(row => row.col1 > 3);
console.log(filteredDf);

// Sort by column
const sortedDf = df.sortBy('col1', 'desc');
console.log(sortedDf);

// Group by column and aggregate
const groupedDf = df.groupBy('col1');
console.log(groupedDf);

Applying Functions

    const { Pandas } = require('jspandas');

    // Create some sample data
    const data = [
    { col1: 1, col2: 2, col3: 3 },
    { col1: 4, col2: 5, col3: 6 },
    { col1: 7, col2: 8, col3: 9 }
    ];

    const df = Pandas.DataFrame(data);

    // Apply function to columns
    const dfColumnsApplied = df.apply(value => value * 2, 0);
    console.log(dfColumnsApplied);

    // Apply function to rows
    const dfRowsApplied = df.apply(row => {
    row['colSum'] = row['col1'] + row['col2'];
    return row;
    }, 1);
    console.log(dfRowsApplied);

Package Sidebar

Install

npm i jspandas

Weekly Downloads

11

Version

1.0.9

License

MIT

Unpacked Size

40.7 kB

Total Files

26

Last publish

Collaborators

  • maityashis123