问题描述
想象一下,我有一个庞大的数据集,partitionBy('id')
。假设id对一个人来说是唯一的,因此每个id可以有n行,目的是将其减少为一。
基本上,进行聚合以使ID彼此不同。
w = Window().partitionBy(id).rowsBetween(-sys.maxsize,sys.maxsize)
test1 = {
key: F.first(key,True).over(w).alias(key)
for key in some_dict.keys()
if (some_dict[key] == 'test1')
}
test2 = {
key: F.last(key,True).over(w).alias(k)
for k in some_dict.keys()
if (some_dict[k] == 'test2')
}
假设我有some_dict
,其值分别为test1或test2,并基于该值,我采用第一个或最后一个,如上所示。
我如何实际调用聚合并减少聚合?
cols = {**test1,**test2}
cols = list(cols.value())
df.select(*cols).groupBy('id').agg(*cols) # Doesnt work
以上内容显然无效。有任何想法吗? 目标是:我有5个唯一ID和25行,每个ID有5行。我希望将其从25行减少到5行。
解决方法
假设您的数据框名称df包含以下方法的重复使用
if (isset($_GET['uin'])) {
$ID = $_GET['uin'];
} else {
$ID = "";
}
$tblemployees_data = array();
$sql_query = "SELECT firstName,lastName,email,department,recoffr,mobileno
FROM tblemployees
WHERE uin = ?";
if ($query_category->prepare($sql_query)) {
// Bind your variables to replace the ?s
$query_category->bind_param('s',$ID);
// Execute query
$query_category->execute();
// store result
$query_category->store_result();
$query_category->bind_result($previous_category_image);
$query_category->fetch();
$query_category->close();
}
在有特定条件的情况下按条件更改顺序,以便特定记录位于分区顶部