a-pandas-ex-melt-pivot-tools


Namea-pandas-ex-melt-pivot-tools JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/a_pandas_ex_melt_pivot_tools
SummarySome useful melt / pivot stuff for pandas DataFrames
upload_time2022-12-10 19:30:56
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords pandas dataframe melt pivot
VCS
bugtrack_url
requirements pandas
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Some useful melt / pivot stuff for pandas DataFrames



```python

pip install a-pandas-ex-melt-pivot-tools

```



```python

from a_pandas_ex_melt_pivot_tools import pd_add_stack_melt_tools

pd_add_stack_melt_tools()

import pandas as pd

df = pd.DataFrame(

    {

        "A": ["foo", "foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar"],

        "B": ["one", "one", "one", "two", "two", "one", "one", "two", "two"],

        "C": [

            "small",

            "large",

            "large",

            "small",

            "small",

            "large",

            "small",

            "small",

            "large",

        ],

        "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],

        "E": [2, 4, 5, 5, 6, 6, 8, 9, 9],

    }

)

print('___________________________________')

print(f'{df}\n\n')

print('___________________________________')

print(f"{df.ds_pivot_to_list(columns=['A'])}\n\n")

print(f"{df.ds_pivot_to_list(columns=['A','B'])}\n\n")

print(f"{df.ds_pivot_to_list(columns=['A','B', 'C'],stack=True)}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column(columns=['A'])}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column(columns=['A','B'])}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column(columns=['A','B', 'C'],stack=True)}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A'],stack=True)}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A','B'],stack=True)}\n\n")

print(f"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A','B', 'C'],stack=True)}\n\n")

___________________________________

     A    B      C  D  E

0  foo  one  small  1  2

1  foo  one  large  2  4

2  foo  one  large  2  5

3  foo  two  small  3  5

4  foo  two  small  3  6

5  bar  one  large  4  6

6  bar  one  small  5  8

7  bar  two  small  6  9

8  bar  two  large  7  9

___________________________________

                                            bar  ...      old_columns

old_columns                                      ...                 

B                    [one, one, two, two, None]  ...  [B, B, B, B, B]

C            [large, small, small, large, None]  ...  [C, C, C, C, C]

D                            [4, 5, 6, 7, None]  ...  [D, D, D, D, D]

E                            [6, 8, 9, 9, None]  ...  [E, E, E, E, E]

[4 rows x 3 columns]

                              bar  ... old_columns

                              one  ...            

old_columns                        ...            

C            [large, small, None]  ...   [C, C, C]

D                    [4, 5, None]  ...   [D, D, D]

E                    [6, 8, None]  ...   [E, E, E]

[3 rows x 5 columns]

                         bar                   foo         old_columns

                         one        two        one     two            

old_columns                                                           

D                        NaN        NaN        NaN     NaN      [D, D]

            large  [4, None]  [7, None]     [2, 2]     NaN         NaN

            small  [5, None]  [6, None]  [1, None]  [3, 3]         NaN

E                        NaN        NaN        NaN     NaN      [E, E]

            large  [6, None]  [9, None]     [4, 5]     NaN         NaN

            small  [8, None]  [9, None]  [2, None]  [5, 6]         NaN

                            bar                                  foo

B          [one, one, two, two]            [one, one, one, two, two]

C  [large, small, small, large]  [small, large, large, small, small]

D                  [4, 5, 6, 7]                      [1, 2, 2, 3, 3]

E                  [6, 8, 9, 9]                      [2, 4, 5, 5, 6]

              bar                                    foo                

              one             two                    one             two

C  [large, small]  [small, large]  [small, large, large]  [small, small]

D          [4, 5]          [6, 7]              [1, 2, 2]          [3, 3]

E          [6, 8]          [9, 9]              [2, 4, 5]          [5, 6]

         bar          foo        

         one  two     one     two

D large  [4]  [7]  [2, 2]     NaN

  small  [5]  [6]     [1]  [3, 3]

E large  [6]  [9]  [4, 5]     NaN

  small  [8]  [9]     [2]  [5, 6]

bar  B      one

     C    large

     D        4

     E        6

     B      one

          ...  

foo  E        5

     B      two

     C    small

     D        3

     E        6

Length: 3524, dtype: object

bar  one  C    large

          D        4

          E        6

          C    large

          D        4

               ...  

foo  two  D        3

          E        5

          C    small

          D        3

          E        6

Length: 153, dtype: object

bar  one  large  D    4

                 E    6

          small  D    5

                 E    8

     two  large  D    7

                 E    9

          small  D    6

                 E    9

foo  one  large  D    2

                 E    4

                 D    2

                 E    5

                 D    2

                 E    4

                 D    2

                 E    5

          small  D    1

                 E    2

     two  small  D    3

                 E    5

                 D    3

                 E    6

                 D    3

                 E    5

                 D    3

                 E    6

dtype: object





```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/a_pandas_ex_melt_pivot_tools",
    "name": "a-pandas-ex-melt-pivot-tools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pandas,dataframe,melt,pivot",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/dd/6b/a0f5b1f798982442233745a1c4a8ed402c20f8f4296103b48bc007500339/a_pandas_ex_melt_pivot_tools-0.10.tar.gz",
    "platform": null,
    "description": "\n# Some useful melt / pivot stuff for pandas DataFrames\n\n\n\n```python\n\npip install a-pandas-ex-melt-pivot-tools\n\n```\n\n\n\n```python\n\nfrom a_pandas_ex_melt_pivot_tools import pd_add_stack_melt_tools\n\npd_add_stack_melt_tools()\n\nimport pandas as pd\n\ndf = pd.DataFrame(\n\n    {\n\n        \"A\": [\"foo\", \"foo\", \"foo\", \"foo\", \"foo\", \"bar\", \"bar\", \"bar\", \"bar\"],\n\n        \"B\": [\"one\", \"one\", \"one\", \"two\", \"two\", \"one\", \"one\", \"two\", \"two\"],\n\n        \"C\": [\n\n            \"small\",\n\n            \"large\",\n\n            \"large\",\n\n            \"small\",\n\n            \"small\",\n\n            \"large\",\n\n            \"small\",\n\n            \"small\",\n\n            \"large\",\n\n        ],\n\n        \"D\": [1, 2, 2, 3, 3, 4, 5, 6, 7],\n\n        \"E\": [2, 4, 5, 5, 6, 6, 8, 9, 9],\n\n    }\n\n)\n\nprint('___________________________________')\n\nprint(f'{df}\\n\\n')\n\nprint('___________________________________')\n\nprint(f\"{df.ds_pivot_to_list(columns=['A'])}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list(columns=['A','B'])}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list(columns=['A','B', 'C'],stack=True)}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column(columns=['A'])}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column(columns=['A','B'])}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column(columns=['A','B', 'C'],stack=True)}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A'],stack=True)}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A','B'],stack=True)}\\n\\n\")\n\nprint(f\"{df.ds_pivot_to_list_no_old_index_column_transposed(columns=['A','B', 'C'],stack=True)}\\n\\n\")\n\n___________________________________\n\n     A    B      C  D  E\n\n0  foo  one  small  1  2\n\n1  foo  one  large  2  4\n\n2  foo  one  large  2  5\n\n3  foo  two  small  3  5\n\n4  foo  two  small  3  6\n\n5  bar  one  large  4  6\n\n6  bar  one  small  5  8\n\n7  bar  two  small  6  9\n\n8  bar  two  large  7  9\n\n___________________________________\n\n                                            bar  ...      old_columns\n\nold_columns                                      ...                 \n\nB                    [one, one, two, two, None]  ...  [B, B, B, B, B]\n\nC            [large, small, small, large, None]  ...  [C, C, C, C, C]\n\nD                            [4, 5, 6, 7, None]  ...  [D, D, D, D, D]\n\nE                            [6, 8, 9, 9, None]  ...  [E, E, E, E, E]\n\n[4 rows x 3 columns]\n\n                              bar  ... old_columns\n\n                              one  ...            \n\nold_columns                        ...            \n\nC            [large, small, None]  ...   [C, C, C]\n\nD                    [4, 5, None]  ...   [D, D, D]\n\nE                    [6, 8, None]  ...   [E, E, E]\n\n[3 rows x 5 columns]\n\n                         bar                   foo         old_columns\n\n                         one        two        one     two            \n\nold_columns                                                           \n\nD                        NaN        NaN        NaN     NaN      [D, D]\n\n            large  [4, None]  [7, None]     [2, 2]     NaN         NaN\n\n            small  [5, None]  [6, None]  [1, None]  [3, 3]         NaN\n\nE                        NaN        NaN        NaN     NaN      [E, E]\n\n            large  [6, None]  [9, None]     [4, 5]     NaN         NaN\n\n            small  [8, None]  [9, None]  [2, None]  [5, 6]         NaN\n\n                            bar                                  foo\n\nB          [one, one, two, two]            [one, one, one, two, two]\n\nC  [large, small, small, large]  [small, large, large, small, small]\n\nD                  [4, 5, 6, 7]                      [1, 2, 2, 3, 3]\n\nE                  [6, 8, 9, 9]                      [2, 4, 5, 5, 6]\n\n              bar                                    foo                \n\n              one             two                    one             two\n\nC  [large, small]  [small, large]  [small, large, large]  [small, small]\n\nD          [4, 5]          [6, 7]              [1, 2, 2]          [3, 3]\n\nE          [6, 8]          [9, 9]              [2, 4, 5]          [5, 6]\n\n         bar          foo        \n\n         one  two     one     two\n\nD large  [4]  [7]  [2, 2]     NaN\n\n  small  [5]  [6]     [1]  [3, 3]\n\nE large  [6]  [9]  [4, 5]     NaN\n\n  small  [8]  [9]     [2]  [5, 6]\n\nbar  B      one\n\n     C    large\n\n     D        4\n\n     E        6\n\n     B      one\n\n          ...  \n\nfoo  E        5\n\n     B      two\n\n     C    small\n\n     D        3\n\n     E        6\n\nLength: 3524, dtype: object\n\nbar  one  C    large\n\n          D        4\n\n          E        6\n\n          C    large\n\n          D        4\n\n               ...  \n\nfoo  two  D        3\n\n          E        5\n\n          C    small\n\n          D        3\n\n          E        6\n\nLength: 153, dtype: object\n\nbar  one  large  D    4\n\n                 E    6\n\n          small  D    5\n\n                 E    8\n\n     two  large  D    7\n\n                 E    9\n\n          small  D    6\n\n                 E    9\n\nfoo  one  large  D    2\n\n                 E    4\n\n                 D    2\n\n                 E    5\n\n                 D    2\n\n                 E    4\n\n                 D    2\n\n                 E    5\n\n          small  D    1\n\n                 E    2\n\n     two  small  D    3\n\n                 E    5\n\n                 D    3\n\n                 E    6\n\n                 D    3\n\n                 E    5\n\n                 D    3\n\n                 E    6\n\ndtype: object\n\n\n\n\n\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Some useful melt / pivot stuff for pandas DataFrames",
    "version": "0.10",
    "split_keywords": [
        "pandas",
        "dataframe",
        "melt",
        "pivot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9b23fc14fd2c2453cb21be5f50043648",
                "sha256": "02f5b806322c1c02cbab025b432a3bea62d6647d32e944210e10db2973b63cbb"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_melt_pivot_tools-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b23fc14fd2c2453cb21be5f50043648",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7148,
            "upload_time": "2022-12-10T19:30:54",
            "upload_time_iso_8601": "2022-12-10T19:30:54.603894Z",
            "url": "https://files.pythonhosted.org/packages/90/72/38227a4761419e0fcc5858a5877ce54aad34d51e1a426d4fec5f37c79231/a_pandas_ex_melt_pivot_tools-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "1aac98661e8804ca846b9cc08e75baec",
                "sha256": "eb275f71d287bc54bda9ec27036159ae57d0d8141b3dfa43ed17b6011f2a053f"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_melt_pivot_tools-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "1aac98661e8804ca846b9cc08e75baec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6025,
            "upload_time": "2022-12-10T19:30:56",
            "upload_time_iso_8601": "2022-12-10T19:30:56.647582Z",
            "url": "https://files.pythonhosted.org/packages/dd/6b/a0f5b1f798982442233745a1c4a8ed402c20f8f4296103b48bc007500339/a_pandas_ex_melt_pivot_tools-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-10 19:30:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "a_pandas_ex_melt_pivot_tools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pandas",
            "specs": []
        }
    ],
    "lcname": "a-pandas-ex-melt-pivot-tools"
}
        
Elapsed time: 0.04656s