在两个日期之间过滤 Pyspark 数据框

时间:2021-06-27 11:57:59

标签: date pyspark

我有一个 pyspark 数据框,如下所示。我只需要 2017-12-17 和 2017-12-19 之间的 target_date 行,这两个日期都包括在内。 输入:

+-------+-----------+------------+
|     id|target_date|order_before|
+-------+-----------+------------+
|1471783| 2017-12-16|           2|
|1471885| 2017-12-16|           2|
|1472928| 2017-12-17|           2|
|1476917| 2017-12-17|           2|
|1477469| 2017-12-18|           1|
|1478190| 2017-12-19|           4|
+-------+-----------+------------+

我需要的输出如下所示。

+-------+-----------+------------+
|     id|target_date|order_before|
+-------+-----------+------------+
|1472928| 2017-12-17|           2|
|1476917| 2017-12-17|           2|
|1477469| 2017-12-18|           1|
|1478190| 2017-12-19|           4|
+-------+-----------+------------+

1 个答案:

答案 0 :(得分:0)

您只需使用 df.filter("target_date between '2017-12-17' and '2017-12-19'").show(truncate=False) +-------+-----------+------------+ |id |target_date|order_before| +-------+-----------+------------+ |1472928|2017-12-17 |2 | |1476917|2017-12-17 |2 | |1477469|2017-12-18 |1 | |1478190|2017-12-19 |4 | +-------+-----------+------------+

TextField(
                                     textDirection: ????????,
                                      maxLines: 20,
                                      minLines: 1,
                                      style: TextStyle(fontSize: 17),
                                      controller: _textMessage,
                                      decoration: InputDecoration(
                                        fillColor: Colors.white,
                                        filled: true,
                                        enabledBorder: OutlineInputBorder(
                                          borderSide:
                                          BorderSide(color: Colors.yellowAccent),
                                          borderRadius: BorderRadius.circular(20),
                                        ),
                                        focusedBorder: OutlineInputBorder(
                                          borderSide:
                                          BorderSide(color: Colors.yellowAccent),
                                          borderRadius: BorderRadius.circular(20),
                                        ),
                                      ),
                                      onChanged: (str){
                                        setState(() {
                                          text = str;
                                        });
                                      },
                                    ),