尝试在Databricks-Koalas中复制熊猫功能 在熊猫中:
View.OnClickListener onClickListener_button1 = new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i=1; i<= 5; i++){
textView.setText("hello " + i);
try{Thread.sleep(1000);
} catch(Exception e){
}
}
}
在考拉中:
df = pd.DataFrame({'a': [450, 1, 26],
'b': [1, 450, 70],
})
thresh = [x for x in range(26)] # create a list 1 to 25
df["c"] = np.where((df.a.isin(thresh) | df.b.isin(thresh)), 1, 0) # find the values within the threshold and flag column 'c'
df
# returns
Out[32]:
a b c
0 450 1 1
1 1 450 1
2 26 70 0
如何按预期正确使用df = ks.DataFrame({'a': [450, 1, 26],
'b': [1, 450, 70],
})
thresh = [x for x in range(26)] # create a list 1 to 25
df = df.assign(c=np.where((df.a.isin(thresh) | df.b.isin(thresh)), 1, 0)) # find the values within the threshold and flag column 'c'
# returns
PandasNotImplementedError: The method `pd.Series.__iter__()` is not implemented. If you want to collect your data as an NumPy array, use 'to_numpy()' instead.
或将Numpy结果包装在ks.Series()中,以便assign()接受结果?
to_numpy
给出与上述相同的错误。
有没有办法在考拉中复制熊猫功能?
答案 0 :(得分:1)
要执行此操作,您不需要在ks.DataFrame
中进行np.where
,但是可以使用astype
:
df = df.assign(c= (df.a.isin(thresh) | df.b.isin(thresh)).astype(int) )
df
a b c
0 450 1 1
1 1 450 1
2 26 70 0