Python 请帮我纠正以下错误
代码:Python 请帮我纠正以下错误,python,markov-chains,Python,Markov Chains,代码: df_paths = df.groupby('cookie')['channel'].aggregate( lambda x: x.unique().tolist()).reset_index() df_last_interaction = df.drop_duplicates('cookie', keep='last')[['cookie', 'conversion']] df_paths = pd.merge(df_paths, df_last_interactio
df_paths = df.groupby('cookie')['channel'].aggregate(
lambda x: x.unique().tolist()).reset_index()
df_last_interaction = df.drop_duplicates('cookie', keep='last')[['cookie', 'conversion']]
df_paths = pd.merge(df_paths, df_last_interaction, how='left', on='cookie')
df_paths['path'] = np.where(
df_paths['conversion'] == 0,
['Start'] + df_paths['channel'] + ['Null'],
['Start'] + df_paths['channel'] + ['Conversion'])
df_paths = df_paths[['cookie', 'path']]
错误:
df_paths = df.groupby('cookie')['channel'].aggregate(
lambda x: x.unique().tolist()).reset_index()
df_last_interaction = df.drop_duplicates('cookie', keep='last')[['cookie', 'conversion']]
df_paths = pd.merge(df_paths, df_last_interaction, how='left', on='cookie')
df_paths['path'] = np.where(
df_paths['conversion'] == 0,
['Start'] + df_paths['channel'] + ['Null'],
['Start'] + df_paths['channel'] + ['Conversion'])
df_paths = df_paths[['cookie', 'path']]
TypeError回溯(最近一次调用上次)
/usr/local/lib/python3.6/dist-packages/pandas/core/ops/array_ops.py在na_算术运算中(左、右、运算、str_rep)
148试试:
-->149结果=表达式。求值(op,str_rep,左,右)
150除类型错误外:
9帧
TypeError:必须是str,而不是list
在处理上述异常期间,发生了另一个异常:
TypeError回溯(最近一次调用上次)
/usr/local/lib/python3.6/dist-packages/pandas/core/ops/array_ops.py在masked_arith_op(x,y,op)中
96.其他:
97如果不是标量(y):
--->98提升类型错误(类型(y))
99
100#遮罩仅对x有意义
类型错误: