Jul-05-2018, 03:29 AM
(This post was last modified: Jul-05-2018, 03:29 AM by answerquest.)
Hi, I'm using Tornado web server and have a similar situation. There's not much to do actually.. the file's contents come as a bytestring. Assuming you've gotten the contents into a variable 'file1' as OP mentioned,
As to how I got that file's contents into a variable, here's a shortened snippet and I'm guessing the structure should be similar in your framework.
On the HTML side:
Python side:
df = pd.read_csv( io.BytesIO(file1) )should do the job. Do
import io
at the top of your code.As to how I got that file's contents into a variable, here's a shortened snippet and I'm guessing the structure should be similar in your framework.
On the HTML side:
<p><input type="file" name="file1"></p>
Python side:
import pandas as pd import io # skipping the tornado specific code... class hydGTFS(tornado.web.RequestHandler): def post(self): print( self.request.files['file1'][0]['filename'] ) df = pd.read_csv( io.BytesIO( self.request.files['file1'][0]['body']) ) print(df.head()) self.write('ok got it bro')
Output:Corridor 1 Week days detail..csv
Run Id Run Description Trip Id Regulation Period Group Line Id
0 49 4901 6144 Default {new group} 47
1 49 4901 6144 Default {new group} 47
2 49 4901 6144 Default {new group} 47
3 49 4901 6144 Default {new group} 47
4 49 4901 6141 Default {new group} 37