导入 count() 数据以在散景中使用

Importing count() data for use within bokeh

我正在尝试使用导入到 Databricks 环境中的散景包创建可视化。我已将数据从原始数据帧转换为类似于以下内容(尽管更大):

columns = ['month', 'title']
data = [('2020-05', 'Paper 1'), ('2020-05', 'Paper 2'), ('2020-03', 'Paper 3'), ('2020-02', 'Paper 4'), ('2020-01', 'Paper 5')]

从那里开始,我希望使用 bokeh 包创建一个折线图来显示每月发布的论文数量(过去 12 个月)。我已经开始使用下面的代码:

df = df.groupBy('month').count().orderBy('month', ascending = False).limit(12)
df = df.orderBy('month', ascending = True)

它以正确的顺序生成了我需要的 table 个结果。但是,当我使用下面的代码尝试将结果数据(从上面的 df)转换为线图时,我收到了一个错误。

代码:

Month = []
Papers = []

for row in df.rdd.collect():
  Month.append(row.month)
  Papers.append(int(row.count))
    
print(Month)
print(Papers)

p = figure(title="Graph to show the release of new papers from January 2020", x_axis_label="Month", y_axis_label="Year")

p.line(Month, Papers, line_width=2)
show(p)

错误:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'

现在,我只能假设这是因为我正在尝试使用由 'built in function' 创建的 'count' 列来为我的绘图创建变量。我的问题是,是否有不同的方法来创建我的 table 结果,以便 bokeh 将此 'count' 列识别为字符串或 int,而不是内置函数?

countRow的一个方法,所以不能用点号得到Rowcount列。相反,您可以使用方括号表示法,例如

for row in df.rdd.collect():
  Month.append(row['month'])
  Papers.append(int(row['count']))