Issue
I have path '/Users/OneDrive/Desktop/Data_CSV' in this path I have 3 folders in each folder 5 folders in each folder 12 csv data.
how can i import total?
what I can. I can only import a whole folder, but folders in folders in folders I can not do well.
this code is for one Ordner:
import glob
import os
import pandas as pd
directory = '/Users/OneDrive/Desktop/Data_CSV'
all_files = glob.glob(os.path.join(directory, "*.csv"))
your_list = [ ]
for filename in all_files:
dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
your_list.append(dataframe)
print(dataframe)
Solution
You can iterate through the folders recursively
import glob
# root_dir needs a trailing slash (i.e. /root/dir/)
for filename in glob.iglob(directory + '**/*.txt', recursive=True):
dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
your_list.append(dataframe)
Answered By - Himanshuman Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.