python-3.x - 散景列可按数字排序
问题描述
如何让bokeh
表格按浮点值而不是字符串值对列进行排序?我有浮点数据,该列继续作为字符串排序,因此它没有按升序/降序正确排序。附上数据和代码片段。
数据:
GB, 15.789, /path/to/A, size, 100.0
GB, 600.123, /path/to/B, size, 100.0
GB, 70.456, /path/to/C, size, 100.0
片段:
#!/usr/bin/env python3
from bokeh.io import output_file, show, save
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, NumberFormatter
def get_data():
lines = open('json.tmp', 'r').read().splitlines()
data = {
'unit': [],
'value': [],
'location': [],
'type': [],
'tol': [],
}
for line in lines:
words = line.split(',')
data['unit'].append(words[0])
data['value'].append(words[1])
data['location'].append(words[2])
data['type'].append(words[3])
data['tol'].append(words[4])
return data
if __name__ == "__main__":
data = get_data()
output_file("data_table.html")
source = ColumnDataSource(data)
columns = [
TableColumn(field="location", title="Path"),
TableColumn(field="value", title="Value", formatter=NumberFormatter(format="0.0")),
TableColumn(field="unit", title="Unit", width=10),
TableColumn(field="type", title="Type", width=20)
]
data_table = DataTable(source=source, columns=columns)
save(data_table)
解决方案
推荐阅读
- c++ - 凯撒密码:如何计算移位值> 10(或更大)?
- c# - 如何在winforms应用程序中制作甘特图?
- python - 布尔值更改时的 Pandas 增量值
- python - 如何使用 css_parser 来获取这个属性?
- go - JWT 认证策略
- compiler-construction - 在低级中间代码中计算数组和其他非标量的活跃度
- javascript - 如何根据javascript中的多个键对数组进行分组和转换?
- ios - 从字符串数组中查找最常见的子字符串
- python-3.x - 网页抓取,python,请求,下载 pdf 文件,身份验证
- qr-code - 对 QR 码的每个部分进行着色,例如计时模式和格式信息