在 dask 数据框中构建一个组合列进行排序

build a combined coloumn in dask dataframe for sorting

基于这个答案我想动态构建组合列

df_post['sort_column'] = df_post.apply(lambda r:str([r[col1],r[col2],r[col3]]), axis=1)
df_post = df_post.set_index('sort_column')
df_post = df_post.map_partitions(lambda x: x.sort_index())

我无法根据配置文件提供的列列表找到使此“[r[col1],r[col2],r[col3]]”动态化的方法。

很难判断后面的问题是什么,但假设它是 "I would like to apply the solution in a the linked answer, but for a list of column names"。这看起来像

df_post['sort_column'] = df_post.apply(lambda r:str([r[c] for c in columns]), axis=1)
df_post = df_post.set_index('sort_column')
df_post = df_post.map_partitions(lambda x: x.sort_index())

其中 columns 已预先从配置文件中获取。