python - 将html页面中选择的文件加载到pandas
问题描述
我正在尝试自动化 Winross(市场研究工具)表语法以生成开放式表。我需要为此使用两个 excel 文件,我打算为此使用 Pandas。我不确定如何将 excel 文件加载到使用 input type =“file”在 HTML 中选择的 pandas 中。
在下面添加 HTML 和 python 代码
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>OE Tables</title>
</head>
<body>
<form class="" action="getfile" method="post" enctype="multipart/form-data">
<h1>OE Tables Generator</h1>
<h3>Select OE data:</h3>
<input type="file" name="myfile" value=""><br><br>
<input type="submit" name="" value="Upload OE File"><br><br>
<h3>Select Code-frame:</h3>
<input type="file" name="myfile" value=""><br><br>
<input type="submit" name="" value="Upload Code-frame"><br <br>
</form>
</body>
</html>
from flask import Flask, render_template, request
import pandas as pd
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route('/getfile', methods=['GET', 'POST'])
def getfile():
if request.method == 'POST':
excel_file = request.files['myfile']
oedata = pd.read_excel(excel_file)
return oedata.head()
else:
result = request.args.get['myfile']
return result
当前得到一个页面,错误如下: Internal Server Error 服务器遇到内部错误,无法完成您的请求。服务器过载或应用程序出错。
解决方案
推荐阅读
- mongodb - 将对象的 MongoDb 中的字段更新为对象数组 - 命令行
- java - 即使在项目中检测到错误,eclipse有没有办法运行Java程序?
- c# - ASP.NET 我无法让模型将数据带回控制器。它始终为 0
- excel - VBA 的问题 - 复制模板工作表并使用输入框重命名
- python - XML到Python中的字典到DataFrame
- vba - 如何将数字日期转换为字符日期,月份名称位于表单的不同字段中?(使用权)
- qt - Qt5 Openvino opencv cmake windows
- javascript - 使用日期时间字段填充 chartjs ajax
- ios - URLImage 永远不会在 SwiftUI 的小部件应用中加载图像
- excel - Excel VBA:将每个工作表名称更改为每个工作表中的单元格 A1 值