astroboy1
astroboy1

Reputation: 197

unable to create excel data using pandas python

I'm trying to create an excel file and try to open it and perform some operations on that data.

file_path = 'd:/files/'
file_folder = 'new_files'
file_name = 'sample.xlsx'

def export(data):
    data.to_excel("{}/{}".format(downloadpath(), downloadfile()), index=False)
    excel_data = open("{}/{}".format(downloadpath(), downloadfile()), 'rb')
    # excel_data_operations

def downloadpath():
     PATH = os.path.join(file_path, file_folder)

     if not os.path.isdir(PATH):
         return os.makedirs(PATH)
    
     return PATH

def downloadfile():
    return file_name
     

I'm trying to do this, but getting end up with

FileNotFoundError: [Errno 2] No such file or directory: 'None/sample.xlsx'

Upvotes: 0

Views: 38

Answers (2)

Laurent
Laurent

Reputation: 13478

In the definition of downloadpath:

  • replace return os.makedirs(PATH)
  • with os.makedirs(PATH)

Upvotes: 1

Dima Berehovets
Dima Berehovets

Reputation: 250

The string 'd:/files/' says that you use windows. In windows, the file path should use backslashes '\'. Try to change the string to d:\files\

Upvotes: 0

Related Questions