Giter Site home page Giter Site logo

mframe's Introduction

MFrame - A minimal DataFrame

maintenance  version  build

A lightweight single file DataFrame implementation that works on older Python distrubtions such as Jython.

I use it with Java data tools such as Streamsets.

Feel free to fork, add tests and features and make a pull request.

Install

$ pip install mframe

or copy mframe.py to your project folder.

Usage

It's goal is to be familar to pandas users without promising 100% compatability. My workflow usually involves writing the code in a Jupyter notebook using Python 3 and then testing it with Jython before deploying it to Streamsets.

Please see the test file for more usage examples.

>>> from mframe import DataFrame
>>> data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
>>> df = DataFrame(data)
>>> df
{'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
>>> df.pd #  the pd alias returns a pandas dataframe, useful for printing in Jupyter when developing
     col_1 col_2
0      3     a
1      2     b
2      1     c
3      0     d
>>> df['col_1'] # Subscript access
[3, 2, 1, 0]
>>> df.col_1 # Attribute access
[3, 2, 1, 0]
>>> df[df.col_1 > 1] # filtering works
     col_1 col_2
0      3     a
1      2     b
>>> df[(df.col_1 > 1) & (df.col_2 == 'a')]
     col_1 col_2
0      3     a
>>> df['col_1'] = df.col_1.apply(str) # Apply is available
>>> df.col_1
['3', '2', '1', '0']
>>> list(df.iterrows()) # returns a generator of dictionaries
[{'col_1': '3', 'col_2': 'a'}, {'col_1': '2', 'col_2': 'b'}, {'col_1': '1', 'col_2': 'c'}, {'col_1': '0', 'col_2': 'd'}]

Tested on

  • Python 3.7
  • Jython 2.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.