2

I have written a program which exports my Pandas DataFrame to a csv as well as an excel file. However, the problem I am facing is that, randomly, the export function to both the file formats does not work, resulting in me seeing an error stating "No such File Path or Directory".

My code is as follows:

frame3.to_csv('C:/Users/Downloads/ABC_test.csv',index=False)

writer = pd.ExcelWriter('C:/Users/Downloads/ABCD.xlsx', engine='openpyxl')
frame3.to_excel(writer, sheet_name='Sheet1')
writer.save()

The major issue is that this code works sometimes and sometimes it does not! Going by what others have posted here, I tried to add the output directory by the use of

pth1 = os.path.join(r'C:/Users/Downloads/FinalProgram/', output_filename)
frame3.to_csv(pth1)

Sadly, this has no effect on this stubborn error. Would appreciate any help / insights possible on the matter.

1
  • Did you ever find a solution? I am having the same issue with to_csv. Commented May 4, 2016 at 18:09

1 Answer 1

1

Forgot to update - I figured a way around this particular problem: Simply set the working directory for the program to be the output directory (as depicted by the command below), before the calling the 'to_csv' function.

os.chdir('F:/Codelah/')

On a side note, this was an issue I primarily faced on Windows OS - Ubuntu worked like a charm and did not require this workaround! Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to define output path within your frame3.to_excel(writer, sheet_name='Sheet1') function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.