Python 考拉群比->;申请退货';不能插入“;“关键”;,已经存在';

Python 考拉群比->;申请退货';不能插入“;“关键”;,已经存在';,python,pandas,databricks,spark-koalas,Python,Pandas,Databricks,Spark Koalas,我一直在努力解决这个问题,但未能解决它,我得到了当前的数据帧: 将databricks.koalas导入为ks x=ks.DataFrame.from_记录( {'ds':{0:Timestamp('2018-10-06 00:00:00'), 1:时间戳('2017-06-08 00:00:00'), 2:时间戳('2018-10-22 00:00:00'), 3:时间戳('2017-02-08 00:00:00'), 4:时间戳('2019-02-03 00:00:00'), 5:时间戳('

我一直在努力解决这个问题,但未能解决它,我得到了当前的数据帧:

将databricks.koalas导入为ks
x=ks.DataFrame.from_记录(
{'ds':{0:Timestamp('2018-10-06 00:00:00'),
1:时间戳('2017-06-08 00:00:00'),
2:时间戳('2018-10-22 00:00:00'),
3:时间戳('2017-02-08 00:00:00'),
4:时间戳('2019-02-03 00:00:00'),
5:时间戳('2019-02-26 00:00:00'),
6:时间戳('2017-04-15 00:00:00'),
7:时间戳('2017-07-02 00:00:00'),
8:时间戳('2017-04-04 00:00:00'),
9:时间戳('2017-03-20 00:00:00'),
10:时间戳('2018-06-09 00:00:00'),
11:时间戳('2017-01-15 00:00:00'),
12:时间戳('2018-05-07 00:00:00'),
13:时间戳('2018-01-17 00:00:00'),
14:时间戳('2017-07-11 00:00:00'),
15:时间戳('2018-12-17 00:00:00'),
16:时间戳('2018-12-05 00:00:00'),
17:时间戳('2017-05-22 00:00:00'),
18:时间戳('2017-08-13 00:00:00'),
19:时间戳('2018-05-21 00:00:00'),
'store':{0:81,
1: 128,
2: 81,
3: 128,
4: 25,
5: 128,
6: 11,
7: 124,
8: 43,
9: 25,
10: 25,
11: 124,
12: 124,
13: 128,
14: 81,
15: 11,
16: 124,
17: 11,
18: 167,
19: 128},
'股票':{0:1,
1: 236,
2: 3,
3: 9,
4: 36,
5: 78,
6: 146,
7: 20,
8: 12,
9: 12,
10: 15,
11: 25,
12: 10,
13: 7,
14: 0,
15: 230,
16: 80,
17: 6,
18: 110,
19: 8},
'销售':{0:1.0,
1: 17.0,
2: 1.0,
3: 2.0,
4: 1.0,
5: 2.0,
6: 7.0,
7: 1.0,
8: 1.0,
9: 1.0,
10: 2.0,
11: 1.0,
12: 1.0,
13: 1.0,
14: 1.0,
15: 1.0,
16: 1.0,
17: 3.0,
18: 2.0,
19: 1.0}}
)
我想在groupby-apply中使用这个函数:

将numpy导入为np
def计算指示器(df):
返回(
df.copy()
.分配(
指标=λx:x['a']
其中df是一个数据帧。如果我使用pandas进行分组应用,代码将按预期执行:

import pandas as pd
# This runs
a = pd.DataFrame.from_dict(x.to_dict()).groupby('store').apply(compute_indicator)
但是,当尝试在考拉上运行相同的操作时,它会给我以下错误:
ValueError:无法插入存储,已经存在

x.groupby('store').apply(compute_indicator)
# ValueError: cannot insert store, already exists
我无法在
compute\u indicator
中使用键入注释,因为有些列不是固定的(它们随数据帧一起移动,意味着要由其他转换使用)


我应该怎么做才能在考拉中运行代码?

对于考拉0.29.0,当
koalas.DataFrame.groupby(key).apply(f)
第一次在一个非类型化的函数上运行
f
时,它必须推断模式,并运行
pandas.DataFrame.head(n).groupby(key).apply(f)
。问题是pandas
apply
接收数据帧作为参数,groupby键作为索引和列(请参见此)

然后,
pandas.DataFrame.head(h).groupby(keys).apply(f)
的结果将转换为
koalas.DataFrame
,因此如果
f
没有删除
列,由于列名重复,此转换将引发异常(请参阅)