Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas read_csv from FileStorage in Flask

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.

like image 218
Dmitry Sazhnev Avatar asked Sep 11 '25 03:09

Dmitry Sazhnev


1 Answers

If you are receiving your csv as a string try it using StringIO:

from io import StringIO
pd.read_csv(StringIO(request.file['file']))
like image 57
zipa Avatar answered Sep 13 '25 16:09

zipa