Coder Social home page Coder Social logo

Comments (2)

rbeesley avatar rbeesley commented on July 23, 2024

Alternatively, make the library an extension of pandas.core.generic.NDFrame, and then these statistics can be ran against Series as well as DataFrames, and they don't have to be instantiated as a separate object. This would allow you to do an import and use it directly on a DataFrame:

import pandas as pd
from pandas.core.generic import NDFrame

def monkeypatch_method(cls):
    def decorator(func):
        setattr(cls, func.__name__, func)
        return func
    return decorator

@monkeypatch_method(NDFrame)
def summary(self):
    """Does the same as dfs = DataFrameSummary(self); dfs[column]"""
    dfs = DataFrameSummary(self)
    dfs.__getitem__(self,column)

Then it could be used like this:

import pandas as pd
import pandas_summary

df = pd.DataFrame({'num_legs': [2, 4, 8, 0],
                   'num_wings': [2, 0, 0, 0],
                   'num_specimen_seen': [10, 2, 1, 8]},
                  index=['falcon', 'dog', 'spider', 'fish'])

df['num_legs'].summary()

instead of:

import pandas as pd
from pandas_summary import DataFrameSummary

df = pd.DataFrame({'num_legs': [2, 4, 8, 0],
                   'num_wings': [2, 0, 0, 0],
                   'num_specimen_seen': [10, 2, 1, 8]},
                  index=['falcon', 'dog', 'spider', 'fish'])

dfs = DataFrameSummary(df)
dfs['num_legs']

The above code is untested, but generally correct with how it'd be exposed and used. I think this makes more sense than using properties and is more like DataFrame.describe() in how it is called, but providing the additional information DataFrameSummary class provides... the summary. It's just more tightly integrated.

Developed as an extension library like this, it could be brought to Pandas in the future more easily.

from traceml.

mmourafiq avatar mmourafiq commented on July 23, 2024

@rbeesley this is an interesting idea.

from traceml.

Related Issues (14)

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.