gpt4 book ai didi

python - Python 3 上的 Lambda

转载 作者:行者123 更新时间:2023-11-30 22:00:47 25 4
gpt4 key购买 nike

我有一个包含 2 列的数据框,我想将其分为两个数组。我知道在 Python 2 中我可以使用这个:

result = spark.sql("SELECT acoustic_data, time_to_failure from df order by acoustic_data asc")
result_rdd = result.rdd.sample(False, 0.0001).map(lambda row: (row.acoustic_data, row.time_to_failure))
result_signal = result_rdd.filter(lambda (acoustic_data, time_to_failure): acoustic_data).collect()

其他列也是如此。

但是如果我现在尝试这样做,我会收到此错误:

TypeError: () missing 1 required positional argument: 'time_to_failure'

result_rdd 返回此:

result_rdd

所以我想从中获取 2 个数组。

问候

最佳答案

Python 3 removed tuple parameter unpacking ,所以这不再有效:

lambda (acoustic_data, time_to_failure): acoustic_data

将其替换为:

lambda acoustic_data_and_time_to_failure: acoustic_data_and_time_to_failure[0]

关于python - Python 3 上的 Lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54234349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com