sql - Spark获取2个特定行之间的行
问题描述
我想获取值在 ('2/1/2020' 和 '2/5/2020') 之间的行
我试过了:
df.select([c for c in df.columns if c > '2/1/2020' & c < '2/5/2020']).show()
但我得到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
TypeError: unsupported operand type(s) for &: 'str' and 'str'
因为标题是 csv 类型(日期)谢谢!
解决方案
而不是&
使用and
布尔运算符。
df.select([c for c in df.columns if c > '2/1/2020' and c < '2/5/2020']).show()
Example:
df=spark.createDataFrame([(1,2,3,4,5,6)],['pro','2/1/2020','2/2/2020','2/3/2020','2/4/2020','2/5/2020'])
df.select([c for c in df.columns if c > '2/1/2020' and c < '2/5/2020']).show()
#+--------+--------+--------+
#|2/2/2020|2/3/2020|2/4/2020|
#+--------+--------+--------+
#| 3| 4| 5|
#+--------+--------+--------+
推荐阅读
- c# - 如何将对象转换为类型?
- javascript - 从外部重新加载 vue 组件
- ios - ios: 将 pod 作为框架导入到 aswift ios 项目中,而不使用 cocoapods
- swift - SwiftUI 中的可选绑定
- python-3.x - 如何在python中删除Nan值?
- python-3.x - 对于共享 IP 地址的多个 Flask 站点,Certbot 证书在 Apache 上不起作用
- typescript - 使用列表和对象作为 Typescript 中的参数覆盖函数
- c++ - C++:使用 Stroustrup 示例生成随机数?
- python - 在 Maya 中查询 AOV 存在
- ionic-framework - 从登录和注册页面隐藏 IonMenu