修复分配值列表给数据框行时的错误
当我执行这段代码时:
import pandas as pd
# Example DataFrame creation
df = pd.DataFrame({'A': [1, 2, 3]}, index=[0, 1, 2])
# Assuming idx is a valid index in df, for example:
idx = 1
# Store the list as a single value in the DataFrame
df.loc[idx, 'SHAP'] = [1, 2]
print(df)
我遇到了一个错误:ValueError: Must have equal len keys and value when setting with an iterable
,我该怎么解决这个问题?我使用的是 pandas 版本 2.1.4
0 个回答
暂无回答