bokeh p中的NaN值

2024-06-08 05:29:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我早些时候在bokeh的google小组上提出了这个问题,并从Sarah Bird提供的有用答案中学到了不少东西,只是为了把答案贴在这里,对于任何遇到类似情况的人。当时我用的是bokeh0.9.2。在

我试图为一批商业租赁建立一个气泡图,其中:

  1. x轴代表租约结束的日期(日期时间:2015-2020)
  2. y轴代表租金水平(浮动:200-500)
  3. 圆的大小/半径表示前提的大小(浮动:200-8000-GFA)
  4. 圆圈颜色代表楼层#(整数:1-40)

我的尝试:

import pandas as pd
import numpy as np
from bokeh.io import output_notebook, show, output_file
from bokeh.plotting import figure, ColumnDataSource
from datetime import datetime
output_notebook()

PATH = ''
filename = 'test_RR.xlsx'
df = pd.read_excel(PATH + filename)

df['TA_END'] = np.where(pd.isnull(df['ET Date']), df.L_END, np.where(df['ET Date'] < df.L_END, df['ET Date'], df.L_END)) # just some data cleaning, don't bother with this

GFA_SCALE_FACTOR = 2
df['GFA_radius'] = np.sqrt( df.GFA / np.pi ) * GFA_SCALE_FACTOR

import seaborn as sns
colors = list(sns.cubehelix_palette(28, start=.5, rot=-.75))
hex_colors = np.array(['#%02x%02x%02x' % (c[0]*255, c[1]*255, c[2]*255) for c in colors])
df['color'] = hex_colors[df.FL - 4]

尝试时出错:

^{pr2}$

错误消息使我认为序列化日期时间的方式有问题:

ValueError: month must be in 1..12

我将把莎拉的答案贴在答案里。在


Tags: 答案fromimportdfoutputdateasnp
1条回答
网友
1楼 · 发布于 2024-06-08 05:29:03

这个问题,实际上是因为数据帧“df”的“ET Date”列中的一个NaN值,虽然与绘图无关,但导致bokeh的序列化失败。在

所以如果我这么做:

source = ColumnDataSource(df[['TA_END', 'Eff Rent', 'GFA_radius', 'color']])

一切都会好起来的。在

一个好的提示是始终只从所需的列中生成ColumnDataSource,因为这样一来,在 比你需要的浏览器-也是从莎拉。在

不过,我希望bokeh可以处理一些NaN数据,因为有些图可能会时不时地显示一个空槽。在

相关问题 更多 >

    热门问题