【问题标题】:How to round a no index dataframe in Dask?如何在 Dask 中舍入无索引数据框?
【发布时间】:2021-02-14 21:32:38
【问题描述】:

我试图在 Dask 中将 2 个数据帧与浮点类型系列合并(由于内存问题,我不能使用纯 Pandas)。从the post,我发现合并浮点型列时会出现问题。所以我相应地尝试了帖子中的答案,以获得 XYZ 值 * 100 并转换为 int。

x                       y                       z                   R   G   B
39020.470001199995750   33884.200004600003012   36.445701600000000  25  39  26
39132.740005500003463   33896.049995399996988   30.405698800000000  19  24  18
39221.059997600001225   33787.050003099997411   26.605699500000000  115 145 145
39237.370010400001775   33773.019996599992737   30.205699900000003  28  33  37
39211.370010400001775   33848.270004300000437   32.535697900000002  19  28  25

我做了什么

N = 100
df2.x = np.round(df2.x*N).astype(int) 
df2.head()

但是由于这个dataframe没有索引,所以会报错

local variable 'index' referenced before assignment

预期的答案

x       y       z       R   G   B
3902047 3388420 3644    25  39  26

【问题讨论】:

标签: python pandas numpy dataframe dask


【解决方案1】:

我遇到了同样的问题并让它以这种方式工作:

df2.x = (df2.x*N).round().astype(int)

如果需要四舍五入到特定的小数:

(df2.x*N).round(2)

【讨论】:

    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    相关资源
    最近更新 更多