【发布时间】:2016-02-18 08:35:48
【问题描述】:
我有一个熊猫数据框。例如,我有以下内容:
column1 column2 column3
34 nan 3
45 nan 1
45 nan 3
45 nan 3
46 nan 3
45 nan nan
45 nan 3
47 nan 5
45 nan 3
50 nan 3
我想使用Theil Sen 进行一些回归。我写了以下脚本:
def LR(df)
line = {}
slope = {}
for k, v in df.iteritems():
if v.empty:
pass # This is to check if a column is empty
else:
xm = np.ma.masked_array(df.index.values, mask=np.isnan(df[k]).compressed()
ym = np.ma.masked_array(df[k], mask=np.isnan(df[k]).compressed()
res = stats.theislopes(ym, xm, 0.90)
line[k] = res[1] + res[0] * xm
slope[k] = res[0]
return line, slope
问题是我有这个错误:
ValueError: failed to create intent(cache|hide)|optional array-- 必须有定义的维度但得到 (0,)。
当我使用调试模式时,似乎在特定列为空时发生错误。
真正的问题是什么?
【问题讨论】:
标签: python python-2.7 pandas scipy statsmodels