我有一个包含不同列的数据框,其中一列是结构数组:
+----------+---------+--------------------------------------+
|id |title | values|
+----------+---------+--------------------------------------+
| 1 | aaa | [{name1, id1}, {name2, id2},...]|
| 2 | bbb | [{name11, id11}, {name22, id22},...]|
Run Code Online (Sandbox Code Playgroud)
此列的 df 架构如下所示:
|-- values: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- name: string (nullable = true)
| | |-- id: long (nullable = true)
Run Code Online (Sandbox Code Playgroud)
我想从这个数组列中提取每个值,如下所示:
+----------+---------+--------------+
|id |title |name | _id|
+----------+---------+--------------+
| 1 | aaa | name1 | id1 |
| 1 | aaa | name2 …Run Code Online (Sandbox Code Playgroud) 我有一个带有两列的数据框:
+--------+-----+
| col1| col2|
+--------+-----+
|22 | 12.2|
|1 | 2.1|
|5 | 52.1|
|2 | 62.9|
|77 | 33.3|
Run Code Online (Sandbox Code Playgroud)
我想创建一个新的数据框,它将仅包含行
“ col1的值”>“ col2的值”
就像要注意的那样,col1具有long类型,而col2具有double类型
结果应该是这样的:
+--------+----+
| col1|col2|
+--------+----+
|22 |12.2|
|77 |33.3|
Run Code Online (Sandbox Code Playgroud) 我有一些带有"date"列的DataFrame,并且我试图生成一个新的DataFrame,其中包含该"date"列的最小和最大日期之间的所有每月时间戳记。
解决方案之一如下:
month_step = 31*60*60*24
min_date, max_date = df.select(min_("date").cast("long"), max_("date").cast("long")).first()
df_ts = spark.range(
(min_date / month_step) * month_step,
((max_date / month_step) + 1) * month_step,
month_step
).select(col("id").cast("timestamp").alias("yearmonth"))
df_formatted_ts = df_ts.withColumn(
"yearmonth",
f.concat(f.year("yearmonth"), f.lit('-'), format_string("%02d", f.month("yearmonth")))
).select('yearmonth')
df_formatted_ts.orderBy(asc('yearmonth')).show(150, False)
Run Code Online (Sandbox Code Playgroud)
问题是我花了month_step31天的时间,但这并不正确,因为有些月份有30天,甚至28天。有可能以某种方式使其更加精确吗?
请注意:以后我只需要年和月的值,所以我将忽略日期和时间。但是无论如何,因为我正在生成一个很大的日期范围(在2001年至2018年之间)之间的时间戳,所以时间戳在变化。
这就是为什么有时会跳过几个月的原因。例如,此快照缺少2010-02:
|2010-01 |
|2010-03 |
|2010-04 |
|2010-05 |
|2010-06 |
|2010-07 |
Run Code Online (Sandbox Code Playgroud)
我检查了一下,从2001年到2018年仅跳过了3个月。
我在一页上有多个 ModalDialog,每个对话框都应具有不同的宽度。每个模式对话框的定制可以在.CSS中进行,其中将覆盖类.modal-dialog
我想知道如何在不接触 .CSS 的情况下为每个模式对话框设置不同的宽度大小。因为每个模式窗口都有 .modal-dialog 类,我无法更改名称,因为它将使用模式窗口创建。
有什么办法吗AttributeModifier?
public class MainPanel extends Panel {
private final ModalDialog modalDialog;
public MainPanel(String id, IModel<String> headingIdx, IModel<String> collapseIdx) {
super(id);
setOutputMarkupId(true);
modalDialog = new ModalDialog("modalDialog");
modalDialog.add(new DefaultTheme());
modalDialog.trapFocus();
modalDialog.closeOnEscape();
add(modalDialog);
add(new AjaxLink<Void>("showModalDialog") {
@Override
public void onClick(AjaxRequestTarget target) {
modalDialog.setContent(new ModalPanel("content", MainPanel.this){
@Override
protected void close(AjaxRequestTarget target) {
modalDialog.close(target);
}
});
modalDialog.open(target);
}
});
add(modalDialog);
}
}
Run Code Online (Sandbox Code Playgroud)
.modal-header {
font-weight: bold;
border: none;
}
.modal-dialog {
border-radius: 5px; …Run Code Online (Sandbox Code Playgroud)