1

When I download my CSV file from the FTP server and it contains ~200-500 rows my application works just fine, but when I download a CSV file from the FTP server with only ~1-200 rows I get the error: No columns to parse from file

The CSV contains the headers: "example1";"example2";"example3";"example4"

with rows looking like: "8481832";2022-30-06";GFBG21";4,00

    with open(csv_filename, 'wb') as file:
        ftp.retrbinary(f"RETR {csv_filename}", file.write)
        file_data = pd.read_csv(csv_filename, sep=';', header=0)

Both files are fully identical to each other, just a different amount of rows

Does anyone know if this is a bug, or am i doing something wrong?

1 Answer 1

1

I'm surprised it works for files with line count > 200. You use a context manager and you don't wait the file is closed before reading it. It probably works for other files because the system writes the buffer on disk. You have to de-indent your last line to wait the file be closed properly:

Try:

    with open(csv_filename, 'wb') as file:
        ftp.retrbinary(f"RETR {csv_filename}", file.write)
    file_data = pd.read_csv(csv_filename, sep=';', header=0)
Sign up to request clarification or add additional context in comments.

2 Comments

That worked! Your explanation makes sense why it would work for bigger files but not with the small ones. thank you
"this would work for larger files". Don't be sure of that :-). Certainly, you read lines, but I think you didn't read the whole file and missed the last lines for big file.

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.