EmptyDataError at /upload_reading while reading csv file using pandas

261 views
Skip to first unread message

jakote lejaha

unread,
May 25, 2020, 6:04:45 PM5/25/20
to Django users
Ideally I would have wanted to use the "csv.reader" function, but in this case it becomes complicated as I would like to load the cvs file to my web template before I decide if I want to save it to the database or not. So I opt for reading the file using pandas as it's easy to display the records to the HTML tags. But however, I keep getting the error below. 


File "pandas\_libs\parsers.pyx", line 532, in pandas._libs.parsers.TextReader.__cinit__
    <source code not available>

Exception Type: EmptyDataError at /upload_reading
Exception Value: No columns to parse from file



How do I fix this?



Jason Turner

unread,
May 25, 2020, 8:23:58 PM5/25/20
to django...@googlegroups.com
Are you sure the file is coma delimited? This error is usually because the file is not coma separated. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/72b3aabd-3930-43ab-821f-e43bc23568e4%40googlegroups.com.

jakote lejaha

unread,
May 26, 2020, 5:11:08 AM5/26/20
to Django users
The same very same file works fine for the python "csv.reader" function with the other parameter as (delimiter=",") other than the file itself. 
I recently added names attribute as a parameter to the "pandas.read_csv" function, but I can still not get my table as expected. Instead, I 
get an empty df. Example below:

Empty DataFrame
Columns: [name, date_time, image, place]
Index: []

On Tuesday, May 26, 2020 at 2:23:58 AM UTC+2, J.T. wrote:
Are you sure the file is coma delimited? This error is usually because the file is not coma separated. 

On Mon, May 25, 2020, 5:04 PM jakote lejaha <lejaha...@gmail.com> wrote:
Ideally I would have wanted to use the "csv.reader" function, but in this case it becomes complicated as I would like to load the cvs file to my web template before I decide if I want to save it to the database or not. So I opt for reading the file using pandas as it's easy to display the records to the HTML tags. But however, I keep getting the error below. 


File "pandas\_libs\parsers.pyx", line 532, in pandas._libs.parsers.TextReader.__cinit__
    <source code not available>

Exception Type: EmptyDataError at /upload_reading
Exception Value: No columns to parse from file



How do I fix this?



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Jason Turner

unread,
May 26, 2020, 8:38:58 AM5/26/20
to django...@googlegroups.com
Is the csv something you created? Or was it given to you?

I use pandas extensively & the times I've received that error, the issue has been with the file itself.

Ard there blank line(s) at the top of the file?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4e0a6361-f3f2-4005-ac2a-627f1b5076dc%40googlegroups.com.

jakote lejaha

unread,
May 26, 2020, 9:37:47 AM5/26/20
to django...@googlegroups.com
The file I had created myself but I have realized that the problem was with the path to the file. Django request.POST['file'] uses an "InMemoryUploadedFile"  to handle file upload. And I could not explicitly reference the path of the file from the fileupload input, and parse directly into "pandas.read_csv" function. But, I have managed to manipulate the "csv.read" to work in my favor now. 
Thank you for the suggestions though. Very much appreciated.

Reply all
Reply to author
Forward
0 new messages