Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取属性错误:序列对象没有属性';爆炸';_Python_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 获取属性错误:序列对象没有属性';爆炸';

Python 获取属性错误:序列对象没有属性';爆炸';,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,我正在尝试运行使用explode()的python脚本。在我的本地服务器上,它工作正常,但当我试图在服务器上运行时,它给出了错误 我正在使用以下代码: df_main1 = (df_main1.set_index(['rule_id', 'applied_sql_function1', 'input_condition', 'input_value', 'and_or_not_oprtor', 'output_condition', 'priority_order']).apply(lambda

我正在尝试运行使用explode()的python脚本。在我的本地服务器上,它工作正常,但当我试图在服务器上运行时,它给出了错误

我正在使用以下代码:

df_main1 = (df_main1.set_index(['rule_id', 'applied_sql_function1', 'input_condition', 'input_value', 'and_or_not_oprtor', 'output_condition', 'priority_order']).apply(lambda x: x.astype(str).str.split(',').explode()).reset_index())
我得到的错误是:

("'Series' object has no attribute 'explode'", u'occurred at index comb_fld_order')

问题在于熊猫的不同版本,因为只在更高版本中工作:

0.25.0版中的新版本

尝试:

df_main1=(df_main1.set_索引(['rule_id','applied_sql_function1','input_condition','input_value','and_or_not optor','output_condition','priority_order'])[col str split(','expand=True)。stack()
其中,
col
是要拆分和分解的字符串列的名称


通常,
expand
将执行水平的
分解
,而
堆栈
将所有内容移动到一列中。

我过去常在下面的代码中删除分解()


服务器上的pandas版本是什么?看起来服务器上的pandas版本低于0.25链接的问题不是这个问题的答案。正确答案是jezrael和anky的:服务器上的pandas版本太旧,无法使用
explode()
。它不起作用。它没有给我与explode相同的结果。它添加了额外的索引,对吗?或者其他什么?你能详细说明一下你想要获得的输入/输出吗?很酷-而且很有效,对吗?在这种情况下-我的建议是将我的帖子标记为答案-因为它包含了解决你问题的想法(因此,这并不总是关于结束解决方案,它也意味着给出一个方向)这是正确的答案
df_main1 = (df_main1.set_index(['rule_id', 'applied_sql_function1', 'input_condition', 'input_value', 'and_or_not_oprtor', 'output_condition', 'priority_order'])['comb_fld_order']
                    .astype(str)
                    .str.split(',', expand=True)
                    .stack()
                    .reset_index(level=-1, drop=True)
                    .reset_index(name='comb_fld_order'))