1. Učit se
  2. /
  3. Kurzy
  4. /
  5. Python 中的 Spark SQL 入门

Connected

cvičení

为数据打标签

已提供一个名为 df 的 dataframe,包含列 endword:string、features:vector 和 outvec:vector。请选取 endword 等于 "him" 的行,并新增一个整数列 label,其值为 1。然后使用 union 操作,加入同样数量的 endword 不等于 him 的行,这些新增行的 label = 0。

提醒:在 SQL 中,不等于使用 <> 表达。

Pokyny

100 XP
  • 导入 lit 函数。
  • 选取 endword 为 'him' 的行,并新增一个整数列 label,值为 1。
  • 选取 endword 不为 'him' 的行,并新增一个整数列 label,值为 0。
  • 将这两部分进行 union,负样本数量与正样本数量相同。