How do I see and customize the source code to Python's defined functions; describe, skew, and kurtosis definitions?

那年仲夏 提交于 2020-06-01 04:46:40

问题


I want to see and customize the python defined functions; describe, skew, and kurtosis. I can't seem to find how to access these functions codes though. I am using Jupyter Lab. Thank you for any help.


回答1:


Seems like you're talking about SciPy functions. Here are the definitions: describe, skew, kurtosis. I found them via the SciPy documentation -- the [source] button. You can customize them by copying the code and changing it in your own module.




回答2:


SOLVED NOW; 1- I checked the notes of describe() to see exactly which file was source. Apparently there are several generic.py files, so this is important.

Fist, I saved the file before any changes as genericBACKUP.py to be safe.

Then each small change to code, I edited the notes with a simple #1, 2, 3 to confirm I was loading the version of file with newest changes that I intended. Note that both terminal and jupyter needed restarting to force the newest saved file with defs to load.

1st - copy entire code of def describe and past it below itself.

2nd - add "SK" onto "def describeSK" to include skew & kurtosis.

3rd - add skew & kurtosis like this to the new def describeSK section;

    def describe_numeric_1d(series):
        stat_index = (
            ["count", "mean", "std", "min"] + formatted_percentiles + ["max", "skew", "kurt"]
        )
        d = (
            [series.count(), series.mean(), series.std(), series.min()]
            + series.quantile(percentiles).tolist()
            + [series.max(), series.skew(), series.kurt()]
        )
        return pd.Series(d, index=stat_index, name=series.name)

My describeSK() output looks like this now. Perfect!

describeSK() output example link



来源:https://stackoverflow.com/questions/60176374/how-do-i-see-and-customize-the-source-code-to-pythons-defined-functions-descri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!