Reputation: 1
new is the main name of the folder, there are still 3subfloders in that main folder. my question is - I would print like the "path and data also"?
import OS
import pandas as pd
import glob
files = OS.listdir("/home/rugved/new")
print(files)
full_data = pd.DataFrame()
for file in files:
path = "/home/rugved/new" + file + "/*.csv"
mod = pd.concat([pd.read_csv(f) for f in glob.glob(path)], ignore_index = True)
full_data = full_data.append(mod)
print(full_data)
ValueError Traceback (most recent call last) /tmp/ipykernel_56324/2862949528.py in 9 for file in files: 10 path = "/home/rugved/new" + file + "/*.csv" ---> 11 mod = pd.concat([pd.read_csv(f) for f in glob.glob(path)], ignore_index = True) 12 full_data = full_data.append(mod) 13
/usr/lib/python3/dist-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy) 242 ValueError: Indexes have overlapping values: ['a'] 243 """ --> 244 op = _Concatenator( 245 objs, 246 axis=axis,
/usr/lib/python3/dist-packages/pandas/core/reshape/concat.py in init(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy, sort) 302 303 if len(objs) == 0: --> 304 raise ValueError("No objects to concatenate") 305 306 if keys is None:
ValueError: No objects to concatenate
Upvotes: -1
Views: 46
Reputation: 180
you can use the
os.walk()
This is brief documentation; I hope it works:
import os
if __name__ == "__main__":
for (root,dirs,files) in os.walk(<main_folder_dir>, topdown=true):
print (root)
print (dirs)
print (files)
print ('--------------------------------')
Upvotes: 0