I'm trying to create pandas dataframe from uploaded csv file without saving file. When I do df = pd.read_csv(request.file['file']) pandas read this as a file but EmptyDataError: No columns to parse from file is shown. But this file is loaded properly to dataframe from console. request.file['file'].stream doesn't work also.
Asked
Active
Viewed 3,597 times
2
Дмитрий Сажнев
- 333
- 3
- 13
-
I had the same problem but, it was solved by using FileStorage.stream. It points to a temporary copy of the file. See the documentation here: https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.FileStorage – Akalanka Weerasooriya May 13 '20 at 11:57
1 Answers
2
If you are receiving your csv as a string try it using StringIO:
from io import StringIO
pd.read_csv(StringIO(request.file['file']))
zipa
- 26,044
- 6
- 38
- 55
-
1
-
3Call `read` method on `FileStorage` object. See - https://stackoverflow.com/a/20017830/2732017 – userx Jun 04 '19 at 11:15