Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

python - How do I loop through all the files of a folder and save the the files in dataframe format with their name of the file?

I have some Bson files along with its json metadata in a folder. I want to access all the Bson files(only) and store them one by one in a pandas dataframe with the same name as the file(the dataframe name will be the same as its file just without without the .bson extension). How to achieve this?

     import bson
     import os
     import pandas as pd
     path_to_bson = 'C:/Users/Lenovo/Documents/home/ubuntu/dump2020'
     bson_files = [pos_bson for pos_bson in os.listdir(path_to_bson) if pos_bson.endswith('.bson')]
     data=[]
     for index,bs in enumerate(bson_files):
         with open(os.path.join(path_to_bson, bs),'rb') as f:
             data=bson.decode_all(f.read())

i think if i proceed this way i should get results but im getting an error

PermissionError: [Errno 13] Permission denied: 'C:/Users/Lenovo/Documents/home/ubuntu/dump2020'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...