Python Forum
Dataload() crash when filename is not found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dataload() crash when filename is not found
#2
import pandas as pd
def dataLoad(filename):
    try:
        data = pd.read_csv(filename,",")
    except FileNotFoundError:
        print("Sorry the file wasn't found")
    else:
        print("Data was succesfully loaded")
        return data
Note that when file not found your function will return None
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Dataload() crash when filename is not found - by buran - Dec-08-2018, 10:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 5 3,770 Nov-23-2020, 05:15 PM
Last Post: cananb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020