I am trying build a webpage which takes a large tab delimited .txt/.txt.gz file as user input from a form and using POST method(test.html) to send the data to cgi-bin directory to file.py which ideally should open the file read and put the data into a dataframe and do some analysis(which i have already wrttien in python and works well on terminal) on the data and send back the analysis results to a html page. That is where the problem i am facing, how to read the data in the file exactly with the separator. How to pass these data into a pandas dataframe with delimiter?
test.html
-
<form enctype = "multipart/form-data" action = "/cgi-bin/file.py" method = "post">
-
<p>File: <input type = "file" name = "filename" /></p>
-
<p><input type = "submit" value = "Upload" /></p>
-
</form>
-
file.py
-
import cgi, os
-
import cgitb; cgitb.enable()
-
import pandas as pd
-
-
form = cgi.FieldStorage()
-
-
fileitem = form['filename']
-
if fileitem.file:
-
message=fileitem.file.read()
-
-
#df = pd.read_csv(message, sep='\t')
-
#some code for analysis
-
#some code for analysis
-
#some code for analysis
-
The 'message' if printed, prints the data without any separator in a single line, this should ideally passed into a pandas dataframe.
Thanks in advance for your time