Python Pandas Dataframe to Nested JSON
How to get desired nested JSON from python dataframe with desired JSON key names
What Is Pandas In Python?
Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. Pandas is an open-source Python package widely used for data science/data analysis and machine learning tasks. It is built on top of another package named Numpy, which supports multi-dimensional arrays.
We can get Pandas dataframe when we query any database like MySQL, SQL Server, PostgreSQL, SQLite, Hive, etc. Pandas make it simple to do many of the time-consuming, repetitive tasks associated with working with data, including:
- Data cleansing
- Data fill
- Data normalization
- Merges and joins
- Data visualization
- Statistical analysis
- Data inspection
- Loading and saving data
I had a use case where I need to query the database and convert the data into a nested JSON with custom key names instead of column names. This was a tricky task as using Pandas lambda functions it…