[英]Adding a new column to an existing Koalas Dataframe results in NaN's
I am trying to add a new column to my existing Koalas dataframe.我正在尝试向我现有的 Koalas dataframe 添加一个新列。 But the values turn into NaN's as soon as the new column is added.
但是一旦添加了新列,这些值就会变成 NaN。 I am not sure what's going on here, could anyone give me some pointers?
我不确定这里发生了什么,有人可以给我一些指示吗?
Here's the code:这是代码:
import databricks.koalas as ks
kdf = ks.DataFrame(
{'a': [1, 2, 3, 4, 5, 6],
'b': [100, 200, 300, 400, 500, 600],
'c': ["one", "two", "three", "four", "five", "six"]},
index=[10, 20, 30, 40, 50, 60])
ks.set_option('compute.ops_on_diff_frames', True)
ks_series = ks.Series((np.arange(len(kdf.to_numpy()))))
kdf["values"] = ks_series
ks.reset_option('compute.ops_on_diff_frames')
You need to match the index when adding a new column:添加新列时需要匹配索引:
import databricks.koalas as ks
import numpy as np
kdf = ks.DataFrame(
{'a': [1, 2, 3, 4, 5, 6],
'b': [100, 200, 300, 400, 500, 600],
'c': ["one", "two", "three", "four", "five", "six"]},
index=[10, 20, 30, 40, 50, 60])
ks.set_option('compute.ops_on_diff_frames', True)
ks_series = ks.Series(np.arange(len(kdf.to_numpy())), index=kdf.index.tolist())
kdf["values"] = ks_series
kdf
a b c values
10 1 100 one 0
20 2 200 two 1
30 3 300 three 2
40 4 400 four 3
50 5 500 five 4
60 6 600 six 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.