我有一个包含汽车数据的数据框。 我需要在pandas dataframe中执行groupby惟一值,并在Flask视图中返回输出,这将允许用户选择汽车的制造商和型号。你知道吗
我所拥有的是
编辑:
cars = carsDF.groupby('manufacturer')['model'].unique().to_json()
该代码的输出如下:
{
"BMW": ["118", "320"],
"Citroen": ["c3", "ax"],
"Hyundai": ["tucson"],
"Mazda": ["3"],
"Mercedes-Benz": ["c-klasa"],
"Opel": ["vectra", "astra"],
"Renault": ["scenic", "megane", "twingo"],
"VW": ["touran"],
"Volvo": ["v40"]
}
所以烧瓶应用程序看起来是这样的:
@app.route('/index')
def index():
cars = carsDF.groupby('manufacturer')['model'].unique().to_json()
return render_template('index.html', cars=cars)
到目前为止,我的观点只是基本的 索引.html地址:
<html>
<body>
<h1>List of cars:</h1>
<div><p>{{ cars }} </b></p></div>
</body>
</html>
它按原样播种汽车。 我需要把它交出来索引.html格式允许我建立级联列表..类似于this的东西,用户可以在其中选择制造商,然后选择型号。你知道吗
我已经设法解决了。 以下是带有数据集的jquery:
JSFIDDLE DEMO
相关问题 更多 >
编程相关推荐