我试图查找特定元素(int/string 类型)是否存在于我的列表中。但我使用断言来评估我的条件,这意味着如果断言条件状态为真(元素存在于列表中),则为假表示元素不在列表中。
这就是我正在尝试的-
def test(x):
try:
for i in x:
assert i==210410
return True
except AssertionError as msg:
print('Error')
x=[210410,'ABC',21228,'YMCA',31334,'KJHG']
Run Code Online (Sandbox Code Playgroud)
即使该元素位于列表中,输出也会导致错误。你能帮我解决这个问题吗?
我正在尝试使用 PySpark 用均值填充 NaN 值。以下是我正在使用的代码,以下是发生的错误:
from pyspark.sql.functions import avg
def fill_with_mean(df_1, exclude=set()):
stats = df_1.agg(*(avg(c).alias(c) for c in df_1.columns if c not in exclude))
return df_1.na.fill(stats.first().asDict())
res = fill_with_mean(df_1, ["MinTemp", "MaxTemp", "Evaporation", "Sunshine"])
res.show()
Run Code Online (Sandbox Code Playgroud)
错误:
Py4JJavaError Traceback (most recent call last)
<ipython-input-35-42f4d984f022> in <module>()
3 stats = df_1.agg(*(avg(c).alias(c) for c in df_1.columns if c not in exclude))
4 return df_1.na.fill(stats.first().asDict())
----> 5 res = fill_with_mean(df_1, ["MinTemp", "MaxTemp", "Evaporation", "Sunshine"])
6 res.show()
5 frames
/usr/local/lib/python3.7/dist-packages/py4j/protocol.py in get_return_value(answer,
gateway_client, target_id, name)
326 …Run Code Online (Sandbox Code Playgroud)