Skip to main content

Pandas DataFrame to nested dict

# from: https://stackoverflow.com/a/74810722/15096247



$pip install a-pandas-ex-to-dict



from a_pandas_ex_to_dict import pd_add_df_to_nested_dict

import pandas as pd

from pprint import pprint



pd_add_df_to_nested_dict()



df = pd.read_csv("https://github.com/pandas-dev/pandas/raw/main/doc/data/titanic.csv")

df = df[:10]

dfdict2 = df.d_to_nested_dict(["Survived", "Pclass", "Embarked", "Fare", "Cabin"])

dfdict = df.d_to_nested_dict()

pprint(dfdict2)

pprint(dfdict)





{0: {1: {'S': {51.8625: {'E46': 1}}},

     3: {'Q': {8.4583: {}}, 'S': {7.25: {}, 8.05: {}, 21.075: {}}}},

 1: {1: {'C': {71.2833: {'C85': 1}}, 'S': {53.1: {'C123': 1}}},

     2: {'C': {30.0708: {}}},

     3: {'S': {7.925: {}, 11.1333: {}}}}}

{1: {0: {3: {'Braund, Mr. Owen Harris': {'male': {22.0: {1: {0: {'A/5 21171': {7.25: 1}}}}}}}}},

 2: {1: {1: {'Cumings, Mrs. John Bradley (Florence Briggs Thayer)': {'female': {38.0: {1: {0: {'PC 17599': {71.2833: 1}}}}}}}}},

 3: {1: {3: {'Heikkinen, Miss. Laina': {'female': {26.0: {0: {0: {'STON/O2. 3101282': {7.925: 1}}}}}}}}},

 4: {1: {1: {'Futrelle, Mrs. Jacques Heath (Lily May Peel)': {'female': {35.0: {1: {0: {'113803': {53.1: 1}}}}}}}}},

 5: {0: {3: {'Allen, Mr. William Henry': {'male': {35.0: {0: {0: {'373450': {8.05: 1}}}}}}}}},

 6: {0: {3: {'Moran, Mr. James': {'male': {}}}}},

 7: {0: {1: {'McCarthy, Mr. Timothy J': {'male': {54.0: {0: {0: {'17463': {51.8625: 1}}}}}}}}},

 8: {0: {3: {'Palsson, Master. Gosta Leonard': {'male': {2.0: {3: {1: {'349909': {21.075: 1}}}}}}}}},

 9: {1: {3: {'Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)': {'female': {27.0: {0: {2: {'347742': {11.1333: 1}}}}}}}}},

 10: {1: {2: {'Nasser, Mrs. Nicholas (Adele Achem)': {'female': {14.0: {1: {0: {'237736': {30.0708: 1}}}}}}}}}}

Metadata

Release files for a-pandas-ex-to-dict 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for a-pandas-ex-to-dict 0.10
File Size Uploaded Provenance Actions
a_pandas_ex_to_dict-0.10.tar.gz 3.9 kB Without provenance Details for a_pandas_ex_to_dict-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for a-pandas-ex-to-dict 0.10
File Interpreter ABI Platform Actions
a_pandas_ex_to_dict-0.10-py3-none-any.whl Python 3 none any Details for a_pandas_ex_to_dict-0.10-py3-none-any.whl

Total release size: 9.8 kB

Release files / a_pandas_ex_to_dict-0.10.tar.gz

Download URL a_pandas_ex_to_dict-0.10.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c24720374fa01295f2178a6fc9f51a75c9cb19a868436ecddaed70cf888640f6
BLAKE2b-256 checksum
How to use checksums
5a87281275b8824ec035c95eeaabac7031ebefbeca7a4bdb95d5d01e49ae91ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / a_pandas_ex_to_dict-0.10-py3-none-any.whl

Download URL a_pandas_ex_to_dict-0.10-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c472b44fca645b5b2bfb417031e9b297b319ccb3f661c12551d49dfbbb80257
BLAKE2b-256 checksum
How to use checksums
3f1615235a3959523bb9430a62d0eb71742baebd3014c600e2b312af1030eeaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for a-pandas-ex-to-dict 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page