{"id":28225520,"url":"https://github.com/hansalemaos/nested2dataframe","last_synced_at":"2026-05-04T22:32:23.306Z","repository":{"id":199567694,"uuid":"703269795","full_name":"hansalemaos/nested2dataframe","owner":"hansalemaos","description":"Transforms a nested dictionary or iterable into a Pandas DataFrame","archived":false,"fork":false,"pushed_at":"2023-10-10T23:41:41.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T10:28:22.462Z","etag":null,"topics":["convert","dataframe","dict","dictionary","iterable","json","nested","pandas"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/nested2dataframe","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hansalemaos.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-10T23:41:22.000Z","updated_at":"2023-10-10T23:42:02.000Z","dependencies_parsed_at":"2023-10-11T01:36:46.946Z","dependency_job_id":null,"html_url":"https://github.com/hansalemaos/nested2dataframe","commit_stats":null,"previous_names":["hansalemaos/nested2dataframe"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hansalemaos/nested2dataframe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fnested2dataframe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fnested2dataframe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fnested2dataframe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fnested2dataframe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hansalemaos","download_url":"https://codeload.github.com/hansalemaos/nested2dataframe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fnested2dataframe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32628205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convert","dataframe","dict","dictionary","iterable","json","nested","pandas"],"created_at":"2025-05-18T11:09:00.159Z","updated_at":"2026-05-04T22:32:23.301Z","avatar_url":"https://github.com/hansalemaos.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Transforms a nested dictionary or iterable into a Pandas DataFrame.\r\n\r\n## Tested against Windows / Python 3.11 / Anaconda\r\n\r\n## pip install nested2dataframe\r\n\r\n```python\r\n\t\r\n\r\nThis function takes a nested dictionary or iterable and converts it into a Pandas DataFrame where each level of nesting\r\nis represented as a separate column. The function is designed to handle dictionaries with varying levels of nesting,\r\nand it can handle missing values, such as NaN or None, and fill them with the specified `tmpnone` value.\r\n\r\nParameters:\r\n- it (dict or iterable): The input nested dictionary or iterable.\r\n- key_prefix (str, optional): The prefix to use for naming the columns representing each level of nesting.\r\n  Defaults to \"level_\".\r\n- tmpnone (any, optional): The value to replace NaN or None values in the DataFrame. Defaults to \"NANVALUE\".\r\n- fillna (any, optional): The value to fill NaN values in the final DataFrame. Defaults to pd.NA.\r\n- optimize_dtypes (bool, optional): Whether to optimize the data types of the DataFrame columns. If True,\r\n  it will attempt to reduce memory usage by changing data types where possible. Defaults to True.\r\n\r\nReturns:\r\n- pandas.DataFrame: A Pandas DataFrame where each level of nesting is represented as a separate column.\r\n\r\nExample:\r\n\tfrom nested2dataframe import nestediter2df\r\n\td7 = {\r\n\t\t\"results\": [\r\n\t\t\t{\r\n\t\t\t\t\"end_time\": \"2021-01-21\",\r\n\t\t\t\t\"key\": \"q1\",\r\n\t\t\t\t\"result_type\": \"multipleChoice\",\r\n\t\t\t\t\"start_time\": \"2021-01-21\",\r\n\t\t\t\t\"value\": [\"1\"],\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\t\"end_time\": \"2021-01-21\",\r\n\t\t\t\t\"key\": \"q2\",\r\n\t\t\t\t\"result_type\": \"multipleChoice\",\r\n\t\t\t\t\"start_time\": \"2021-01-21\",\r\n\t\t\t\t\"value\": [\"False\"],\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\t\"end_time\": \"2021-01-21\",\r\n\t\t\t\t\"key\": \"q3\",\r\n\t\t\t\t\"result_type\": \"multipleChoice\",\r\n\t\t\t\t\"start_time\": \"2021-01-21\",\r\n\t\t\t\t\"value\": [\"3\"],\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\t\"end_time\": \"2021-01-21\",\r\n\t\t\t\t\"key\": \"q4\",\r\n\t\t\t\t\"result_type\": \"multipleChoice\",\r\n\t\t\t\t\"start_time\": \"2021-01-21\",\r\n\t\t\t\t\"value\": [\"3\"],\r\n\t\t\t},\r\n\t\t]\r\n\t}\r\n\r\n\tdf77 = nestediter2df(d7)\r\n\tprint(df77.to_string())\r\n\r\n\t#    level_1  level_2 level_3    end_time key     result_type  start_time      0\r\n\t# 0  results        0   value  2021-01-21  q1  multipleChoice  2021-01-21      1\r\n\t# 1  results        1   value  2021-01-21  q2  multipleChoice  2021-01-21  False\r\n\t# 2  results        2   value  2021-01-21  q3  multipleChoice  2021-01-21      3\r\n\t# 3  results        3   value  2021-01-21  q4  multipleChoice  2021-01-21      3\r\n\r\n\r\n\r\n\r\nd1 = {\r\n    \"level1\": {\r\n        \"t1\": {\r\n            \"s1\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n            \"s2\": {\"col1\": 1, \"col2\": 5, \"col3\": 4, \"col4\": 8},\r\n            \"s3\": {\"col1\": 11, \"col2\": 8, \"col3\": 2, \"col4\": 9},\r\n            \"s4\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n        },\r\n        \"t2\": {\r\n            \"s1\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n            \"s2\": {\"col1\": 1, \"col2\": 5, \"col3\": 4, \"col4\": 8},\r\n            \"s3\": {\"col1\": 11, \"col2\": 8, \"col3\": 2, \"col4\": 9},\r\n            \"s4\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n        },\r\n        \"t3\": {\r\n            \"s1\": {\"col1\": 1, \"col2\": 2, \"col3\": 3, \"col4\": 4},\r\n            \"s2\": {\"col1\": 5, \"col2\": 6, \"col3\": 7, \"col4\": 8},\r\n            \"s3\": {\"col1\": 9, \"col2\": 10, \"col3\": 11, \"col4\": 12},\r\n            \"s4\": {\"col1\": 13, \"col2\": 14, \"col3\": 15, \"col4\": 16},\r\n        },\r\n    },\r\n    \"level2\": {\r\n        \"t1\": {\r\n            \"s1\": {\"col1\": 5, \"col2\": 4, \"col3\": 9, \"col4\": 9},\r\n            \"s2\": {\"col1\": 1, \"col2\": 5, \"col3\": 4, \"col4\": 5},\r\n            \"s3\": {\"col1\": 11, \"col2\": 8, \"col3\": 2, \"col4\": 13},\r\n            \"s4\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 20},\r\n        },\r\n        \"t2\": {\r\n            \"s1\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n            \"s2\": {\"col1\": 1, \"col2\": 5, \"col3\": 4, \"col4\": 8},\r\n            \"s3\": {\"col1\": 11, \"col2\": 8, \"col3\": 2, \"col4\": 9},\r\n            \"s4\": {\"col1\": 5, \"col2\": 4, \"col3\": 4, \"col4\": 9},\r\n        },\r\n        \"t3\": {\r\n            \"s1\": {\"col1\": 1, \"col2\": 2, \"col3\": 3, \"col4\": 4},\r\n            \"s2\": {\"col1\": 5, \"col2\": 6, \"col3\": 7, \"col4\": 8},\r\n            \"s3\": {\"col1\": 9, \"col2\": 10, \"col3\": 11, \"col4\": 12},\r\n            \"s4\": {\"col1\": 13, \"col2\": 14, \"col3\": 15, \"col4\": 16},\r\n        },\r\n    },\r\n}\r\n#    level_1 level_2 level_3  col1  col2  col3  col4\r\n# 0   level1      t1      s1     5     4     4     9\r\n# 1   level1      t1      s2     1     5     4     8\r\n# 2   level1      t1      s3    11     8     2     9\r\n# 3   level1      t1      s4     5     4     4     9\r\n# 4   level1      t2      s1     5     4     4     9\r\n# 5   level1      t2      s2     1     5     4     8\r\n# 6   level1      t2      s3    11     8     2     9\r\n# 7   level1      t2      s4     5     4     4     9\r\n# 8   level1      t3      s1     1     2     3     4\r\n# 9   level1      t3      s2     5     6     7     8\r\n# 10  level1      t3      s3     9    10    11    12\r\n# 11  level1      t3      s4    13    14    15    16\r\n# 12  level2      t1      s1     5     4     9     9\r\n# 13  level2      t1      s2     1     5     4     5\r\n# 14  level2      t1      s3    11     8     2    13\r\n# 15  level2      t1      s4     5     4     4    20\r\n# 16  level2      t2      s1     5     4     4     9\r\n# 17  level2      t2      s2     1     5     4     8\r\n# 18  level2      t2      s3    11     8     2     9\r\n# 19  level2      t2      s4     5     4     4     9\r\n# 20  level2      t3      s1     1     2     3     4\r\n# 21  level2      t3      s2     5     6     7     8\r\n# 22  level2      t3      s3     9    10    11    12\r\n# 23  level2      t3      s4    13    14    15    16\r\n\r\n\r\nd3 = [\r\n    {\r\n        \"cb\": ({\"ID\": 1, \"Name\": \"A\", \"num\": 50}, {\"ID\": 2, \"Name\": \"A\", \"num\": 68}),\r\n    },\r\n    {\r\n        \"cb\": ({\"ID\": 1, \"Name\": \"A\", \"num\": 50}, {\"ID\": 4, \"Name\": \"A\", \"num\": 67}),\r\n    },\r\n    {\r\n        \"cb\": (\r\n            {\"ID\": 1, \"Name\": \"A\", \"num\": 50},\r\n            {\"ID\": 6, \"Name\": \"A\", \"num\": 67, \"bubu\": {\"bibi\": 3}},\r\n        ),\r\n    },\r\n]\r\n\r\n#    level_1  level_2    end_time key     result_type  start_time  value\r\n# 0  results        0  2021-01-21  q1  multipleChoice  2021-01-21      1\r\n# 1  results        1  2021-01-21  q2  multipleChoice  2021-01-21  False\r\n# 2  results        2  2021-01-21  q3  multipleChoice  2021-01-21      3\r\n# 3  results        3  2021-01-21  q4  multipleChoice  2021-01-21      x\r\n\r\n\r\ndf33 = nestediter2df(d3)\r\nprint(df33.to_string())\r\n\r\n#    level_1 level_2  level_3 level_4  ID Name  num  bibi\r\n# 0        0      cb        0     NaN   1    A   50  \u003cNA\u003e\r\n# 1        0      cb        1     NaN   2    A   68  \u003cNA\u003e\r\n# 2        1      cb        0     NaN   1    A   50  \u003cNA\u003e\r\n# 3        1      cb        1     NaN   4    A   67  \u003cNA\u003e\r\n# 4        2      cb        0     NaN   1    A   50  \u003cNA\u003e\r\n# 5        2      cb        1    bubu   6    A   67     3\r\n\r\nd4 = {\r\n    \"critic_reviews\": [\r\n        {\"review_critic\": \"XYZ\", \"review_score\": 90},\r\n        {\"review_critic\": \"ABC\", \"review_score\": 90},\r\n        {\"review_critic\": \"123\", \"review_score\": 90},\r\n    ],\r\n    \"genres\": [\"Sports\", \"Golf\"],\r\n    \"score\": 85,\r\n    \"title\": \"Golf Simulator\",\r\n    \"url\": \"http://example.com/golf-simulator\",\r\n}\r\n\r\ndf44 = nestediter2df(d4)\r\nprint(df44.to_string())\r\n\r\n#           level_1  level_2 review_critic  review_score       0     1  score           title                                url\r\n# 0  critic_reviews        0           XYZ            90     NaN   NaN   \u003cNA\u003e             NaN                                NaN\r\n# 1  critic_reviews        1           ABC            90     NaN   NaN   \u003cNA\u003e             NaN                                NaN\r\n# 2  critic_reviews        2           123            90     NaN   NaN   \u003cNA\u003e             NaN                                NaN\r\n# 3          genres     \u003cNA\u003e          \u003cNA\u003e          \u003cNA\u003e  Sports  Golf   \u003cNA\u003e             NaN                                NaN\r\n# 4            \u003cNA\u003e     \u003cNA\u003e          \u003cNA\u003e          \u003cNA\u003e     NaN   NaN     85  Golf Simulator  http://example.com/golf-simulator\r\n\r\nd5 = {\r\n    \"c1\": {\r\n        \"application_contacts\": {\"adress\": \"X\", \"email\": \"test@test.com\"},\r\n        \"application_details\": {\"email\": None, \"phone\": None},\r\n        \"employer\": {\"Name\": \"Nom\", \"email\": \"bibi@baba.com\"},\r\n        \"id\": \"1\",\r\n    },\r\n    \"c2\": {\r\n        \"application_contacts\": {\"adress\": \"Z\", \"email\": None},\r\n        \"application_details\": {\"email\": \"testy@test_a.com\", \"phone\": None},\r\n        \"employer\": {\"Name\": \"Nom\", \"email\": None},\r\n        \"id\": \"2\",\r\n    },\r\n    \"c3\": {\r\n        \"application_contacts\": {\"adress\": \"Y\", \"email\": None},\r\n        \"application_details\": {\"email\": \"testy@test_a.com\", \"phone\": None},\r\n        \"employer\": {\"Name\": \"Nom\", \"email\": None},\r\n        \"id\": \"3\",\r\n    },\r\n}\r\n\r\ndf55 = nestediter2df(d5)\r\nprint(df55.to_string())\r\n\r\n#    level_1               level_2 adress             email phone Name    id\r\n# 0       c1  application_contacts      X     test@test.com  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 1       c1   application_details   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 2       c1              employer   \u003cNA\u003e     bibi@baba.com  \u003cNA\u003e  Nom  \u003cNA\u003e\r\n# 3       c1                  \u003cNA\u003e   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  NaN     1\r\n# 4       c2  application_contacts      Z              \u003cNA\u003e  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 5       c2   application_details   \u003cNA\u003e  testy@test_a.com  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 6       c2              employer   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  Nom  \u003cNA\u003e\r\n# 7       c2                  \u003cNA\u003e   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  NaN     2\r\n# 8       c3  application_contacts      Y              \u003cNA\u003e  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 9       c3   application_details   \u003cNA\u003e  testy@test_a.com  \u003cNA\u003e  NaN  \u003cNA\u003e\r\n# 10      c3              employer   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  Nom  \u003cNA\u003e\r\n# 11      c3                  \u003cNA\u003e   \u003cNA\u003e              \u003cNA\u003e  \u003cNA\u003e  NaN     3\r\n\r\nd6 = {\r\n    \"departure\": [\r\n        {\r\n            \"actual\": None,\r\n            \"actual_runway\": None,\r\n            \"airport\": \"Findel\",\r\n            \"delay\": None,\r\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\r\n            \"estimated_runway\": None,\r\n            \"gate\": None,\r\n            \"iata\": \"LUX\",\r\n            \"icao\": \"ELLX\",\r\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\r\n            \"terminal\": None,\r\n            \"timezone\": \"Europe/Luxembourg\",\r\n        },\r\n        {\r\n            \"actual\": None,\r\n            \"actual_runway\": None,\r\n            \"airport\": \"Findel\",\r\n            \"delay\": None,\r\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\r\n            \"estimated_runway\": None,\r\n            \"gate\": None,\r\n            \"iata\": \"LUX\",\r\n            \"icao\": \"ELLX\",\r\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\r\n            \"terminal\": None,\r\n            \"timezone\": \"Europe/Luxembourg\",\r\n        },\r\n        {\r\n            \"actual\": None,\r\n            \"actual_runway\": None,\r\n            \"airport\": \"Findel\",\r\n            \"delay\": None,\r\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\r\n            \"estimated_runway\": None,\r\n            \"gate\": None,\r\n            \"iata\": \"LUX\",\r\n            \"icao\": \"ELLX\",\r\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\r\n            \"terminal\": None,\r\n            \"timezone\": \"Europe/Luxembourg\",\r\n        },\r\n    ]\r\n}\r\n\r\n\r\ndf66 = nestediter2df(d6)\r\nprint(df66.to_string())\r\n\r\n#      level_1  level_2 actual actual_runway airport delay                  estimated estimated_runway  gate iata  icao                  scheduled terminal           timezone\r\n# 0  departure        0   \u003cNA\u003e          \u003cNA\u003e  Findel  \u003cNA\u003e  2020-07-07T06:30:00+00:00             \u003cNA\u003e  \u003cNA\u003e  LUX  ELLX  2020-07-07T06:30:00+00:00     \u003cNA\u003e  Europe/Luxembourg\r\n# 1  departure        1   \u003cNA\u003e          \u003cNA\u003e  Findel  \u003cNA\u003e  2020-07-07T06:30:00+00:00             \u003cNA\u003e  \u003cNA\u003e  LUX  ELLX  2020-07-07T06:30:00+00:00     \u003cNA\u003e  Europe/Luxembourg\r\n# 2  departure        2   \u003cNA\u003e          \u003cNA\u003e  Findel  \u003cNA\u003e  2020-07-07T06:30:00+00:00             \u003cNA\u003e  \u003cNA\u003e  LUX  ELLX  2020-07-07T06:30:00+00:00     \u003cNA\u003e  Europe/Luxembourg\r\n\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fnested2dataframe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhansalemaos%2Fnested2dataframe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fnested2dataframe/lists"}