【问题标题】:build a combined coloumn in dask dataframe for sorting在 dask 数据框中构建一个组合列以进行排序
【发布时间】:2018-08-31 09:10:20
【问题描述】:

Sorting in Dask

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

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]]”动态的方法。

【问题讨论】:

  • 您能否发布一个具有所需输出的数据示例?

标签: python pandas sorting apply dask


【解决方案1】:

很难说出问题所在,但假设它是“我想在链接的答案中应用解决方案,但要获得列名列表”。这可能看起来像

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是事先从配置文件中获取的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 2018-10-29
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    相关资源
    最近更新 更多