Skip to content

A lightweight JavaScript library for working with tabular data, inspired by Pandas in Python. Built with TypeScript, it provides an intuitive API for data manipulation and analysis.

License

Notifications You must be signed in to change notification settings

rajnish93/jpandas

Repository files navigation

📟 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

About

A lightweight JavaScript library for working with tabular data, inspired by Pandas in Python. Built with TypeScript, it provides an intuitive API for data manipulation and analysis.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published