Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sharath123
Helper I
Helper I

how to get MongoDB nested documents in table format using python?

Capture2.PNG

However the subdocuments will just appear as JSON inside the subdocument cell


from pandas import DataFrame

df = DataFrame(list(db.collection_name.find({}))
print(df)

how can I get a below 2nd table like this using python?

what is the approach for this?

Capture3.PNG

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @sharath123 

You can refer this code

import pandas as pd
from pandas import DataFrame,Series
df = pd.read_csv('1.csv',sep='\t')
df1 = df['address'].apply(eval).apply(Series)
df2 = pd.concat([df,df1],axis = 1)
df2.drop('address',axis =1, inplace = True)
df2.rename(columns={'number':'address.number','street':'address.street','city':'address.city'},inplace = True)
print(df2)

vchenwuzmsft_0-1635477411825.png

 

 

If something wrong please let me know .

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-chenwuz-msft
Community Support
Community Support

Hi @sharath123 

You can refer this code

import pandas as pd
from pandas import DataFrame,Series
df = pd.read_csv('1.csv',sep='\t')
df1 = df['address'].apply(eval).apply(Series)
df2 = pd.concat([df,df1],axis = 1)
df2.drop('address',axis =1, inplace = True)
df2.rename(columns={'number':'address.number','street':'address.street','city':'address.city'},inplace = True)
print(df2)

vchenwuzmsft_0-1635477411825.png

 

 

If something wrong please let me know .

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.