Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import os
  2. import glob
  3.  
  4. for root, dirs, files in os.walk("D:/Test"):
  5. for file in files:
  6. if file.endswith(".xlsx"):
  7. #print(os.path.join(root, file))
  8. s = os.path.join(root, file)
  9. print(s)
  10. all_data = pd.DataFrame()
  11. for f in s:
  12. df = pd.read_excel(f)
  13. all_data = all_data.append(df,ignore_index=True)
  14.  
  15. # now save the data frame
  16. writer = pd.ExcelWriter('result.xlsx')
  17. all_data.to_excel(writer,'sheet1')
  18. writer.save()
  19.  
  20. Traceback (most recent call last):
  21.  
  22. File "<ipython-input-169-41c6d76207e7>", line 12, in <module>
  23. df = pd.read_excel(f)
  24.  
  25. File "C:UsersUserAnaconda3libsite-packagespandasutil_decorators.py", line 118, in wrapper
  26. return func(*args, **kwargs)
  27.  
  28. File "C:UsersUserAnaconda3libsite-packagespandasioexcel.py", line 230, in read_excel
  29. io = ExcelFile(io, engine=engine)
  30.  
  31. File "C:UsersUserAnaconda3libsite-packagespandasioexcel.py", line 294, in __init__
  32. self.book = xlrd.open_workbook(self._io)
  33.  
  34. File "C:UsersUserAnaconda3libsite-packagesxlrd__init__.py", line 116, in open_workbook
  35. with open(filename, "rb") as f:
  36.  
  37. FileNotFoundError: [Errno 2] No such file or directory: 'D'
  38.  
  39. paths = []
  40. for root, dirs, files in os.walk("D:/Test"):
  41. for file in files:
  42. if file.endswith(".xlsx"):
  43. #print(os.path.join(root, file))
  44. s = os.path.join(root, file)
  45. print(s)
  46. paths.append(s)
  47.  
  48. all_data = pd.DataFrame()
  49. for f in paths:
  50. df = pd.read_excel(f)
  51. all_data = all_data.append(df,ignore_index=True)
Add Comment
Please, Sign In to add comment